{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Naive Bayes - Trabalho\n",
    "\n",
    "__Equipe:__\n",
    "* Sayonara Santos Araújo\n",
    "* Lailson Azevedo do Rego\n",
    "\n",
    "\n",
    "## Questão 1\n",
    "\n",
    "Implemente um classifacor Naive Bayes para o problema de predizer a qualidade de um carro. Para este fim, utilizaremos um conjunto de dados referente a qualidade de carros, disponível no [UCI](https://archive.ics.uci.edu/ml/datasets/car+evaluation). Este dataset de carros possui as seguintes features e classe:\n",
    "\n",
    "** Attributos **\n",
    "1. buying: vhigh, high, med, low\n",
    "2. maint: vhigh, high, med, low\n",
    "3. doors: 2, 3, 4, 5, more\n",
    "4. persons: 2, 4, more\n",
    "5. lug_boot: small, med, big\n",
    "6. safety: low, med, high\n",
    "\n",
    "([1, 1, 2, 5, 3, 1, 1])\n",
    "\n",
    "** Classes **\n",
    "1. unacc, acc, good, vgood\n",
    "\n",
    "## Questão 2\n",
    "Crie uma versão de sua implementação usando as funções disponíveis na biblioteca SciKitLearn para o Naive Bayes ([veja aqui](http://scikit-learn.org/stable/modules/naive_bayes.html)) \n",
    "\n",
    "## Questão 3\n",
    "\n",
    "Analise a acurácia dos dois algoritmos e discuta a sua solução."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true,
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "###QUESTAO 1#########\n",
    "################ RESOLUCAO ######################################\n",
    "#\n",
    "#    buying: vhigh, high, med, low\n",
    "#    maint: vhigh, high, med, low\n",
    "#    doors: 2, 3, 4, 5, more\n",
    "#    persons: 2, 4, more\n",
    "#    lug_boot: small, med, big\n",
    "#    safety: low, med, high\n",
    "#\n",
    "#   CAR                      car acceptability\n",
    "#   . PRICE                  overall price\n",
    "#   . . buying               buying price\n",
    "#   . . maint                price of the maintenance\n",
    "#   . TECH                   technical characteristics\n",
    "#   . . COMFORT              comfort\n",
    "#   . . . doors              number of doors\n",
    "#   . . . persons            capacity in terms of persons to carry\n",
    "#   . . . lug_boot           the size of luggage boot\n",
    "#   . . safety               estimated safety of the car\n",
    "#\n",
    "\n",
    "import pandas as pd\n",
    "filename='car.data'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true,
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "dataset = pd.read_csv(filename)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pandas.core.frame.DataFrame"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(dataset)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>vhigh</th>\n",
       "      <th>vhigh.1</th>\n",
       "      <th>2</th>\n",
       "      <th>2.1</th>\n",
       "      <th>small</th>\n",
       "      <th>low</th>\n",
       "      <th>unacc</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>vhigh</td>\n",
       "      <td>vhigh</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>small</td>\n",
       "      <td>med</td>\n",
       "      <td>unacc</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>vhigh</td>\n",
       "      <td>vhigh</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>small</td>\n",
       "      <td>high</td>\n",
       "      <td>unacc</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>vhigh</td>\n",
       "      <td>vhigh</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>med</td>\n",
       "      <td>low</td>\n",
       "      <td>unacc</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>vhigh</td>\n",
       "      <td>vhigh</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>med</td>\n",
       "      <td>med</td>\n",
       "      <td>unacc</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>vhigh</td>\n",
       "      <td>vhigh</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>med</td>\n",
       "      <td>high</td>\n",
       "      <td>unacc</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   vhigh vhigh.1  2 2.1  small   low  unacc\n",
       "0  vhigh   vhigh  2   2  small   med  unacc\n",
       "1  vhigh   vhigh  2   2  small  high  unacc\n",
       "2  vhigh   vhigh  2   2    med   low  unacc\n",
       "3  vhigh   vhigh  2   2    med   med  unacc\n",
       "4  vhigh   vhigh  2   2    med  high  unacc"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dataset.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true,
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "# Nomeando colunas do dataset\n",
    "dataset.columns = ['buying','maint','doors','persons','lug_boot','safety','classs']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>buying</th>\n",
       "      <th>maint</th>\n",
       "      <th>doors</th>\n",
       "      <th>persons</th>\n",
       "      <th>lug_boot</th>\n",
       "      <th>safety</th>\n",
       "      <th>classs</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>vhigh</td>\n",
       "      <td>vhigh</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>small</td>\n",
       "      <td>med</td>\n",
       "      <td>unacc</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>vhigh</td>\n",
       "      <td>vhigh</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>small</td>\n",
       "      <td>high</td>\n",
       "      <td>unacc</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>vhigh</td>\n",
       "      <td>vhigh</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>med</td>\n",
       "      <td>low</td>\n",
       "      <td>unacc</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>vhigh</td>\n",
       "      <td>vhigh</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>med</td>\n",
       "      <td>med</td>\n",
       "      <td>unacc</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>vhigh</td>\n",
       "      <td>vhigh</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>med</td>\n",
       "      <td>high</td>\n",
       "      <td>unacc</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  buying  maint doors persons lug_boot safety classs\n",
       "0  vhigh  vhigh     2       2    small    med  unacc\n",
       "1  vhigh  vhigh     2       2    small   high  unacc\n",
       "2  vhigh  vhigh     2       2      med    low  unacc\n",
       "3  vhigh  vhigh     2       2      med    med  unacc\n",
       "4  vhigh  vhigh     2       2      med   high  unacc"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dataset.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "med      432\n",
       "low      432\n",
       "high     432\n",
       "vhigh    431\n",
       "Name: buying, dtype: int64"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.value_counts(dataset['buying'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true,
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "dataBuying=pd.value_counts(dataset['buying'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>buying</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>med</th>\n",
       "      <td>432</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>low</th>\n",
       "      <td>432</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>high</th>\n",
       "      <td>432</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>vhigh</th>\n",
       "      <td>431</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       buying\n",
       "med       432\n",
       "low       432\n",
       "high      432\n",
       "vhigh     431"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dataframeBuying=pd.DataFrame(dataBuying)\n",
    "type(dataframeBuying)\n",
    "dataframeBuying"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1209, 384, 69, 65)"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# MANIPULAÇÃO DO DATAFRAME PELA CLASSE\n",
    "# FOI IMPLEMENTADO UMA FUNCAO PARA ESSA PARTE!\n",
    "\n",
    "dataClass=pd.value_counts(dataset['classs'])\n",
    "dataframeClass=pd.DataFrame(dataClass)\n",
    "\n",
    "# Filtragem por CLASSE\n",
    "data_class_unacc = dataset.loc[(dataset['classs']=='unacc')]\n",
    "data_class_acc = dataset.loc[(dataset['classs']=='acc')]\n",
    "data_class_good = dataset.loc[(dataset['classs']=='good')]\n",
    "data_class_vgood = dataset.loc[(dataset['classs']=='vgood')]\n",
    "\n",
    "# Quantidade total de elementos por classe\n",
    "total_el_unacc = data_class_unacc['classs'].count()\n",
    "total_el_acc = data_class_acc['classs'].count()\n",
    "total_el_good = data_class_good['classs'].count()\n",
    "total_el_vgood = data_class_vgood['classs'].count()\n",
    "\n",
    "total_el_unacc,total_el_acc,total_el_good,total_el_vgood\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "431 432 432 432 1727\n"
     ]
    }
   ],
   "source": [
    "# MANIPULAÇAO DO DATAFRAME PELO ATRIBUTO BUYING\n",
    "\n",
    "# O PASSO DE FILTRAGEM A SEGUIR JA CONTEM FUNCAO IMPLEMENTADA\n",
    "# FIltragem dos BUYING = 'vhigh'\n",
    "data_vhigh=dataset.loc[(dataset['buying']=='vhigh')]\n",
    "\n",
    "# Filtragem dos BUYNG='high'\n",
    "data_high=dataset.loc[(dataset['buying']=='high')]\n",
    "\n",
    "# Filtragem dos BUYNG='med'\n",
    "data_med=dataset.loc[(dataset['buying']=='med')]\n",
    "\n",
    "# Filtragem dos BUYNG='low'\n",
    "data_low=dataset.loc[(dataset['buying']=='low')]\n",
    "\n",
    "# Filtragem dos BUYNG='vhigh' && CLASS='unacc'\n",
    "data_vhigh_unacc=dataset.loc[(dataset['buying']=='vhigh') & (dataset['classs']=='unacc')]\n",
    "\n",
    "# Filtragem dos BUYNG='high' && CLASS='unacc'\n",
    "data_high_unacc=dataset.loc[(dataset['buying']=='high') & (dataset['classs']=='unacc')]\n",
    "\n",
    "# Filtragem dos BUYNG='med' && CLASS='unacc'\n",
    "data_med_unacc=dataset.loc[(dataset['buying']=='med') & (dataset['classs']=='unacc')]\n",
    "\n",
    "# Filtragem dos BUYNG='low' && CLASS='unacc'\n",
    "data_low_unacc=dataset.loc[(dataset['buying']=='low') & (dataset['classs']=='unacc')]\n",
    "\n",
    "\n",
    "\n",
    "# Filtragem dos BUYNG='vhigh' && CLASS='acc'\n",
    "data_vhigh_acc=dataset.loc[(dataset['buying']=='vhigh') & (dataset['classs']=='acc')]\n",
    "\n",
    "# Filtragem dos BUYNG='high' && CLASS='acc'\n",
    "data_high_acc=dataset.loc[(dataset['buying']=='high') & (dataset['classs']=='acc')]\n",
    "\n",
    "# Filtragem dos BUYNG='med' && CLASS='acc'\n",
    "data_med_acc=dataset.loc[(dataset['buying']=='med') & (dataset['classs']=='acc')]\n",
    "\n",
    "# Filtragem dos BUYNG='low' && CLASS='acc'\n",
    "data_low_acc=dataset.loc[(dataset['buying']=='low') & (dataset['classs']=='acc')]\n",
    "\n",
    "\n",
    "\n",
    "# Filtragem dos BUYNG='vhigh' && CLASS='good'\n",
    "data_vhigh_good=dataset.loc[(dataset['buying']=='vhigh') & (dataset['classs']=='good')]\n",
    "\n",
    "# Filtragem dos BUYNG='high' && CLASS='good'\n",
    "data_high_good=dataset.loc[(dataset['buying']=='high') & (dataset['classs']=='good')]\n",
    "\n",
    "# Filtragem dos BUYNG='med' && CLASS='good'\n",
    "data_med_good=dataset.loc[(dataset['buying']=='med') & (dataset['classs']=='good')]\n",
    "\n",
    "# Filtragem dos BUYNG='low' && CLASS='good'\n",
    "data_low_good=dataset.loc[(dataset['buying']=='low') & (dataset['classs']=='good')]\n",
    "\n",
    "\n",
    "\n",
    "# Filtragem dos BUYNG='vhigh' && CLASS='vgood'\n",
    "data_vhigh_vgood=dataset.loc[(dataset['buying']=='vhigh') & (dataset['classs']=='vgood')]\n",
    "\n",
    "# Filtragem dos BUYNG='high' && CLASS='vgood'\n",
    "data_high_vgood=dataset.loc[(dataset['buying']=='high') & (dataset['classs']=='vgood')]\n",
    "\n",
    "# Filtragem dos BUYNG='med' && CLASS='vgood'\n",
    "data_med_vgood=dataset.loc[(dataset['buying']=='med') & (dataset['classs']=='vgood')]\n",
    "\n",
    "# Filtragem dos BUYNG='low' && CLASS='vgood'\n",
    "data_low_vgood=dataset.loc[(dataset['buying']=='low') & (dataset['classs']=='vgood')]\n",
    "\n",
    "\n",
    "\n",
    "# CONTAGEM DE ELEMENTOS\n",
    "# IMPLEMENTAÇÃO DA FUNCAO FINALIZADA\n",
    "\n",
    "# Quantidade total de elementos\n",
    "total_elementos = dataset['buying'].count()\n",
    "\n",
    "# Total vhigh\n",
    "total_vhigh = data_vhigh['buying'].count()\n",
    "\n",
    "# Total high\n",
    "total_high = data_high['buying'].count()\n",
    "\n",
    "# Total med\n",
    "total_med = data_med['buying'].count()\n",
    "\n",
    "# Total low \n",
    "total_low = data_low['buying'].count()\n",
    "\n",
    "# IMPLEMENTANDO\n",
    "# TABELA DE FREQUENCIA PARA BUYING/CLASS\n",
    "# Total vhigh p/ classe unacc\n",
    "total_vhigh_unacc = data_vhigh_unacc['buying'].count()\n",
    "\n",
    "# Total high p/ classe unacc\n",
    "total_high_unacc = data_high_unacc['buying'].count()\n",
    "\n",
    "# Total med p/ classe unacc\n",
    "total_med_unacc = data_med_unacc['buying'].count()\n",
    "\n",
    "# Total low p/ classe unacc\n",
    "total_low_unacc = data_low_unacc['buying'].count()\n",
    "\n",
    "\n",
    "# Total vhigh p/ classe acc\n",
    "total_vhigh_acc = data_vhigh_acc['buying'].count()\n",
    "\n",
    "# Total high p/ classe acc\n",
    "total_high_acc = data_high_acc['buying'].count()\n",
    "\n",
    "# Total med p/ classe acc\n",
    "total_med_acc = data_med_acc['buying'].count()\n",
    "\n",
    "# Total low p/ classe acc\n",
    "total_low_acc = data_low_acc['buying'].count()\n",
    "\n",
    "\n",
    "# Total vhigh p/ classe good\n",
    "total_vhigh_good = data_vhigh_good['buying'].count()\n",
    "\n",
    "# Total high p/ classe good\n",
    "total_high_good = data_high_good['buying'].count()\n",
    "\n",
    "# Total med p/ classe unacc\n",
    "total_med_good = data_med_good['buying'].count()\n",
    "\n",
    "# Total low p/ classe unacc\n",
    "total_low_good = data_low_good['buying'].count()\n",
    "\n",
    "\n",
    "# Total vhigh p/ classe vgood\n",
    "total_vhigh_vgood = data_vhigh_good['buying'].count()\n",
    "\n",
    "# Total high p/ classe vgood\n",
    "total_high_vgood = data_high_vgood['buying'].count()\n",
    "\n",
    "# Total med p/ classe unacc\n",
    "total_med_vgood = data_med_vgood['buying'].count()\n",
    "\n",
    "# Total low p/ classe unacc\n",
    "total_low_vgood = data_low_vgood['buying'].count()\n",
    "\n",
    "\n",
    "print(total_vhigh,total_high,total_med,total_low,total_elementos)\n",
    "# total_elementos"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "p_unacc_vhigh : 0.8329466357308586\n",
      "p_acc_vhigh : 0.16705336426914155\n",
      "p_good_vhigh : 0.0\n",
      "p_vgood_vhigh : 0.0\n"
     ]
    }
   ],
   "source": [
    "# NAIVE BAYES\n",
    "\n",
    "# P(class|atrib) = [P(atri|class)*P(class)]/P(atrib)\n",
    "\n",
    "# P(ATRIBUTO/CLASS) \n",
    "# P(atributo|uncc)\n",
    "p_vhigh_unacc = total_vhigh_unacc/total_el_unacc\n",
    "p_high_unacc = total_high_unacc/total_el_unacc\n",
    "p_med_unacc = total_med_unacc/total_el_unacc\n",
    "p_low_unacc = total_low_unacc/total_el_unacc\n",
    "\n",
    "# P(atributo|acc)\n",
    "p_vhigh_acc = total_vhigh_acc/total_el_acc\n",
    "p_high_acc = total_high_acc/total_el_acc\n",
    "p_med_acc = total_med_acc/total_el_acc\n",
    "p_low_acc = total_low_acc/total_el_acc\n",
    "\n",
    "# P(atributo|good)\n",
    "p_vhigh_good = total_vhigh_good/total_el_good\n",
    "p_high_good = total_high_good/total_el_good\n",
    "p_med_good = total_med_good/total_el_good\n",
    "p_low_good = total_low_good/total_el_good\n",
    "\n",
    "# P(atributo|vgood)\n",
    "p_vhigh_vgood = total_vhigh_vgood/total_el_vgood\n",
    "p_high_vgood = total_high_vgood/total_el_vgood\n",
    "p_med_vgood = total_med_vgood/total_el_vgood\n",
    "p_low_vgood = total_low_vgood/total_el_vgood\n",
    "\n",
    "# P(vhigh)\n",
    "p_vhigh = total_vhigh/total_elementos\n",
    "\n",
    "# P(high)\n",
    "p_high = total_high/total_elementos\n",
    "\n",
    "# P(med)\n",
    "p_med = total_med/total_elementos\n",
    "\n",
    "# P(low)\n",
    "p_low = total_low/total_elementos\n",
    "\n",
    "# P(class)\n",
    "p_unacc = total_el_unacc/total_elementos\n",
    "p_acc = total_el_acc/total_elementos\n",
    "p_good = total_el_good/total_elementos\n",
    "p_vgood = total_el_vgood/total_elementos\n",
    "\n",
    "# P(uncc|vhigh) = \n",
    "p_unacc_vhigh = (p_vhigh_unacc * p_unacc)/(p_vhigh)\n",
    "\n",
    "# P(acc|vhigh)\n",
    "p_acc_vhigh = (p_vhigh_acc * p_acc)/(p_vhigh)\n",
    "\n",
    "# P(good|vhigh)\n",
    "p_good_vhigh = (p_vhigh_good * p_good)/(p_vhigh)\n",
    "\n",
    "# P(vgood|vhigh)\n",
    "p_vgood_vhigh = (p_vhigh_vgood * p_vgood)/(p_vhigh)\n",
    "\n",
    "#v_p_vhigh[]=p_unacc_vhigh,p_acc_vhigh,p_good_vhigh,p_vgood_vhigh\n",
    "#prob_test = max(v_p_vhigh)\n",
    "\n",
    "print((\"p_unacc_vhigh : {0}\\np_acc_vhigh : {1}\\np_good_vhigh : {2}\\np_vgood_vhigh : {3}\").format(p_unacc_vhigh,p_acc_vhigh,p_good_vhigh,p_vgood_vhigh))\n",
    "\n",
    "# print(p_high_unacc,p_high_acc,p_high_good,p_high_vgood)\n",
    "# print(total_vhigh,total_high,total_med,total_low,p_vhigh,p_high,p_med,p_low,total_elementos)\n",
    "\n",
    "# print(total_med_unacc, total_med_acc, total_med_good,total_med_vgood)\n",
    "# print(total_el_unacc, total_el_acc, total_el_good, total_el_vgood)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['unacc', 'acc', 'vgood', 'good'], dtype=object)"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# LISTA ELEMENTOS UNICOS DE UMA COLUNA\n",
    "teste=dataset.classs.unique()\n",
    "teste\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{0: 0.83294663573085859, 1: 0.74999999999999989, 2: 0.62037037037037035, 3: 0.5972222222222221, 4: 0.83294663573085859, 5: 0.72685185185185186, 6: 0.62037037037037035, 7: 0.62037037037037035, 8: 0.75406032482598606, 9: 0.69444444444444453, 10: 0.67592592592592593, 11: 0.67592592592592593, 12: 1.0, 13: 0.54166666666666663, 14: 0.55902777777777779, 15: 0.78086956521739126, 16: 0.68055555555555558, 17: 0.63888888888888884, 18: 0.61979166666666663, 19: 0.48090277777777768, 20: 1.0} {0: 0.83294663573085859, 1: 0.83294663573085859, 2: 0.75406032482598606, 3: 1.0, 4: 0.78086956521739126, 5: 1.0} 0.408525287187 {0: 0.70005790387955991, 1: 0.22235089751013318, 2: 0.037637521713954833, 3: 0.039953676896352056} {0: 0.2859913562297442, 1: 0.090835964261556462, 2: 0.015375879367190547, 3: 0.016322087328248427} 0\n"
     ]
    }
   ],
   "source": [
    "## NAIVE BAYES ###\n",
    "# # MANIPULAÇÃO DO DATAFRAME PELA CLASSE\n",
    "\n",
    "import pandas as pd\n",
    "filename='car.data'\n",
    "\n",
    "dataset = pd.read_csv(filename)\n",
    "\n",
    "\n",
    "# dataClass=pd.value_counts(dataset['classs'])\n",
    "# dataframeClass=pd.DataFrame(dataClass)\n",
    "\n",
    "# A classe retorna um dicionario de DATAFRAMES e Total elementos de cada Dataframe\n",
    "# Para acessar primeiro dataframe: separatedByClass[0]\n",
    "def separatedByClass(dataset):\n",
    "    class_element_v = dataset.classs.unique()\n",
    "    separatedByClass = {}\n",
    "    total_el_class = {}\n",
    "    for i in range(0,4):\n",
    "        separatedByClass[i] = dataset.loc[(dataset['classs']==class_element_v[i])]\n",
    "        total_el_class[i] = separatedByClass[i]['classs'].count()\n",
    "    return separetedByClass, total_el_class\n",
    "\n",
    "\n",
    "\n",
    "# MANIPULAÇAO DO DATAFRAME PELO ATRIBUTO BUYING\n",
    "\n",
    "# A funcao a seguir retorna a filtragem por atributos de cada coluna\n",
    "# Retorna um dicionario com 21 elementos (0 a 20)\n",
    "def separatedByFeature(dataset):\n",
    "    data_columns = dataset.columns\n",
    "    len_columns = len(data_columns)-1\n",
    "    separatedByFeature = {}\n",
    "    total_el_features = {}\n",
    "    k=0\n",
    "    for i in range(0,len_columns):\n",
    "        feature = dataset[data_columns[i]].unique() # Elementos de cada Feature\n",
    "        len_feature = len(feature)\n",
    "        for j in range(0,len_feature):\n",
    "            data_filter_feature = dataset.loc[(dataset[data_columns[i]] == feature[j])] \n",
    "            separatedByFeature[k] = data_filter_feature\n",
    "            total_el_features[k] = separatedByFeature[k][data_columns[i]].count()\n",
    "            k=k+1\n",
    "    quant_el_features=len(total_el_features)\n",
    "    return separatedByFeature, total_el_features, quant_el_features\n",
    "\n",
    "\n",
    "# A FUNCAO ABAIXO RETORNA UM DIC DE 84 ITENS\n",
    "# É REALIZADO UMA FILTRAGEM DE CADA FEATURE & CADA CLASS. LOGO, SAO 4 DATAFRAMES PARA CADA ELEMENTO DE FEATURE 21*4\n",
    "# EXEMPLO: data_vhigh_unacc=dataset.loc[(dataset['buying']=='vhigh') & (dataset['classs']=='unacc')]\n",
    "def separatedByFeatureClass(dic_separatedByFeature)\n",
    "    separatedByFeature = dic_separatedByFeature\n",
    "    class_element_v = separatedByFeature[0].classs.unique()\n",
    "    len_separatedByFeature = len(separatedByFeature)\n",
    "    separatedByFeatureClass = {}\n",
    "    total_el_feature_class = {}\n",
    "    k = 0\n",
    "    for i in range (0,len_separatedByFeature):\n",
    "        if (i>=0 and i<16):\n",
    "            data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[0])]\n",
    "            separatedByFeatureClass[k] = data_filter_feature_class\n",
    "            total_el_feature_class[k] = separatedByFeatureClass[k]['buying'].count()\n",
    "            k=k+1\n",
    "            data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[1])]\n",
    "            separatedByFeatureClass[k] = data_filter_feature_class\n",
    "            total_el_feature_class[k] = separatedByFeatureClass[k]['buying'].count()\n",
    "            k=k+1\n",
    "            data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[2])]\n",
    "            separatedByFeatureClass[k] = data_filter_feature_class\n",
    "            total_el_feature_class[k] = separatedByFeatureClass[k]['buying'].count()\n",
    "            k=k+1\n",
    "            data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[3])]\n",
    "            separatedByFeatureClass[k] = data_filter_feature_class\n",
    "            total_el_feature_class[k] = separatedByFeatureClass[k]['buying'].count()\n",
    "            k=k+1\n",
    "        elif (i>=16 and i<32):\n",
    "            data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[0])]\n",
    "            separatedByFeatureClass[k] = data_filter_feature_class\n",
    "            total_el_feature_class[k] = separatedByFeatureClass[k]['maint'].count()\n",
    "            k=k+1\n",
    "            data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[1])]\n",
    "            separatedByFeatureClass[k] = data_filter_feature_class\n",
    "            total_el_feature_class[k] = separatedByFeatureClass[k]['maint'].count()\n",
    "            k=k+1\n",
    "            data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[2])]\n",
    "            separatedByFeatureClass[k] = data_filter_feature_class\n",
    "            total_el_feature_class[k] = separatedByFeatureClass[k]['maint'].count()\n",
    "            k=k+1\n",
    "            data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[3])]\n",
    "            separatedByFeatureClass[k] = data_filter_feature_class\n",
    "            total_el_feature_class[k] = separatedByFeatureClass[k]['maint'].count()\n",
    "            k=k+1\n",
    "        elif (i>=32 and i<48):\n",
    "            data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[0])]\n",
    "            separatedByFeatureClass[k] = data_filter_feature_class\n",
    "            total_el_feature_class[k] = separatedByFeatureClass[k]['doors'].count()\n",
    "            k=k+1\n",
    "            data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[1])]\n",
    "            separatedByFeatureClass[k] = data_filter_feature_class\n",
    "            total_el_feature_class[k] = separatedByFeatureClass[k]['doors'].count()\n",
    "            k=k+1\n",
    "            data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[2])]\n",
    "            separatedByFeatureClass[k] = data_filter_feature_class\n",
    "            total_el_feature_class[k] = separatedByFeatureClass[k]['doors'].count()\n",
    "            k=k+1\n",
    "            data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[3])]\n",
    "            separatedByFeatureClass[k] = data_filter_feature_class\n",
    "            total_el_feature_class[k] = separatedByFeatureClass[k]['doors'].count()\n",
    "            k=k+1\n",
    "        elif (i>=48 and i<60):\n",
    "            data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[0])]\n",
    "            separatedByFeatureClass[k] = data_filter_feature_class\n",
    "            total_el_feature_class[k] = separatedByFeatureClass[k]['persons'].count()\n",
    "            k=k+1\n",
    "            data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[1])]\n",
    "            separatedByFeatureClass[k] = data_filter_feature_class\n",
    "            total_el_feature_class[k] = separatedByFeatureClass[k]['persons'].count()\n",
    "            k=k+1\n",
    "            data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[2])]\n",
    "            separatedByFeatureClass[k] = data_filter_feature_class\n",
    "            total_el_feature_class[k] = separatedByFeatureClass[k]['persons'].count()\n",
    "            k=k+1\n",
    "            data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[3])]\n",
    "            separatedByFeatureClass[k] = data_filter_feature_class\n",
    "            total_el_feature_class[k] = separatedByFeatureClass[k]['persons'].count()\n",
    "            k=k+1\n",
    "        elif (i>=60 and i<72):\n",
    "            data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[0])]\n",
    "            separatedByFeatureClass[k] = data_filter_feature_class\n",
    "            total_el_feature_class[k] = separatedByFeatureClass[k]['lug_boot'].count()\n",
    "            k=k+1\n",
    "            data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[1])]\n",
    "            separatedByFeatureClass[k] = data_filter_feature_class\n",
    "            total_el_feature_class[k] = separatedByFeatureClass[k]['lug_boot'].count()\n",
    "            k=k+1\n",
    "            data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[2])]\n",
    "            separatedByFeatureClass[k] = data_filter_feature_class\n",
    "            total_el_feature_class[k] = separatedByFeatureClass[k]['lug_boot'].count()\n",
    "            k=k+1\n",
    "            data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[3])]\n",
    "            separatedByFeatureClass[k] = data_filter_feature_class\n",
    "            total_el_feature_class[k] = separatedByFeatureClass[k]['lug_boot'].count()\n",
    "            k=k+1\n",
    "        elif (i>=72 and i<len_separatedByFeature):\n",
    "            data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[0])]\n",
    "            separatedByFeatureClass[k] = data_filter_feature_class\n",
    "            total_el_feature_class[k] = separatedByFeatureClass[k]['lug_boot'].count()\n",
    "            k=k+1\n",
    "            data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[1])]\n",
    "            separatedByFeatureClass[k] = data_filter_feature_class\n",
    "            total_el_feature_class[k] = separatedByFeatureClass[k]['lug_boot'].count()\n",
    "            k=k+1\n",
    "            data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[2])]\n",
    "            separatedByFeatureClass[k] = data_filter_feature_class\n",
    "            total_el_feature_class[k] = separatedByFeatureClass[k]['lug_boot'].count()\n",
    "            k=k+1\n",
    "            data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[3])]\n",
    "            separatedByFeatureClass[k] = data_filter_feature_class\n",
    "            total_el_feature_class[k] = separatedByFeatureClass[k]['lug_boot'].count()\n",
    "            k=k+1\n",
    "    return separatedByFeatureClass, total_el_feature_class\n",
    "\n",
    "\n",
    "# A função a seguir retorna a probabilidade P(feature/class)\n",
    "def p_FeatureClass(dic_total_el_feature_class,dic_total_el_class):\n",
    "    total_el_feature_class = dic_total_el_feature_class\n",
    "    total_el_class = dic_total_el_class\n",
    "    p_feature_class = {}\n",
    "    k=0\n",
    "    while (k>=0 and k<16):\n",
    "        p_feature_class[k] = total_el_feature_class[k]/total_el_class[0]\n",
    "        k=k+1\n",
    "        p_feature_class[k] = total_el_feature_class[k]/total_el_class[1]\n",
    "        k=k+1\n",
    "        p_feature_class[k] = total_el_feature_class[k]/total_el_class[2]\n",
    "        k=k+1\n",
    "        p_feature_class[k] = total_el_feature_class[k]/total_el_class[3]\n",
    "        k=k+1\n",
    "    while (k>=16 and k<32):\n",
    "        p_feature_class[k] = total_el_feature_class[k]/total_el_class[0]\n",
    "        k=k+1\n",
    "        p_feature_class[k] = total_el_feature_class[k]/total_el_class[1]\n",
    "        k=k+1\n",
    "        p_feature_class[k] = total_el_feature_class[k]/total_el_class[2]\n",
    "        k=k+1\n",
    "        p_feature_class[k] = total_el_feature_class[k]/total_el_class[3]\n",
    "        k=k+1   \n",
    "    while (k>=32 and k<48):\n",
    "        p_feature_class[k] = total_el_feature_class[k]/total_el_class[0]\n",
    "        k=k+1\n",
    "        p_feature_class[k] = total_el_feature_class[k]/total_el_class[1]\n",
    "        k=k+1\n",
    "        p_feature_class[k] = total_el_feature_class[k]/total_el_class[2]\n",
    "        k=k+1\n",
    "        p_feature_class[k] = total_el_feature_class[k]/total_el_class[3]\n",
    "        k=k+1  \n",
    "    while (k>=48 and k<60):\n",
    "        p_feature_class[k] = total_el_feature_class[k]/total_el_class[0]\n",
    "        k=k+1\n",
    "        p_feature_class[k] = total_el_feature_class[k]/total_el_class[1]\n",
    "        k=k+1\n",
    "        p_feature_class[k] = total_el_feature_class[k]/total_el_class[2]\n",
    "        k=k+1\n",
    "        p_feature_class[k] = total_el_feature_class[k]/total_el_class[3]\n",
    "        k=k+1 \n",
    "    while (k>=60 and k<72):\n",
    "        p_feature_class[k] = total_el_feature_class[k]/total_el_class[0]\n",
    "        k=k+1\n",
    "        p_feature_class[k] = total_el_feature_class[k]/total_el_class[1]\n",
    "        k=k+1\n",
    "        p_feature_class[k] = total_el_feature_class[k]/total_el_class[2]\n",
    "        k=k+1\n",
    "        p_feature_class[k] = total_el_feature_class[k]/total_el_class[3]\n",
    "        k=k+1 \n",
    "    while (k>=72 and k<84):\n",
    "        p_feature_class[k] = total_el_feature_class[k]/total_el_class[0]\n",
    "        k=k+1\n",
    "        p_feature_class[k] = total_el_feature_class[k]/total_el_class[1]\n",
    "        k=k+1\n",
    "        p_feature_class[k] = total_el_feature_class[k]/total_el_class[2]\n",
    "        k=k+1\n",
    "        p_feature_class[k] = total_el_feature_class[k]/total_el_class[3]\n",
    "        k=k+1\n",
    "    return p_feature_class\n",
    "\n",
    "# A funcao a seguir retorna o P(feature) ou P(class)\n",
    "def p_Features(dic_total_el_features):\n",
    "    total_el_features = dic_total_el_features\n",
    "    p_feature = {}\n",
    "    len_features = len(total_el_features)\n",
    "    total_elements=0\n",
    "    for i in range (0,4):\n",
    "        total_elements = total_elements+total_el_features[i]\n",
    "\n",
    "    for i in range(0,len_features):\n",
    "        p_feature[i] = total_el_features[i]/total_elements\n",
    "    return p_feature\n",
    "\n",
    "\n",
    "## A classe a seguir retorna a probabilidade de cada atributo das features do problemas##\n",
    "def p_Class_Feature(dic_p_feature_class, dic_p_class, dic_p_feature):\n",
    "    p_feature_class = dic_p_feature_class\n",
    "    p_class = dic_p_class\n",
    "    p_feature = dic_p_feature\n",
    "    p_class_feature = {}\n",
    "    p_class_feature1 = {}\n",
    "    maxx=0\n",
    "    c=0\n",
    "    for k in range(0,4):\n",
    "        p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[0]\n",
    "        if (p_class_feature[k]>maxx):\n",
    "            maxx = p_class_feature[k]\n",
    "        p_class_feature1[0] = maxx\n",
    "        c=c+1\n",
    "\n",
    "    maxx=0\n",
    "    c=0\n",
    "    for k in range(4,8):\n",
    "        p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[1]\n",
    "        if (p_class_feature[k]>maxx):\n",
    "            maxx = p_class_feature[k]\n",
    "        p_class_feature1[1] = maxx\n",
    "        c=c+1\n",
    "\n",
    "    maxx=0\n",
    "    c=0\n",
    "    for k in range(8,12):\n",
    "        p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[2]\n",
    "        if (p_class_feature[k]>maxx):\n",
    "            maxx = p_class_feature[k]\n",
    "        p_class_feature1[2] = maxx\n",
    "        c=c+1\n",
    "    maxx=0\n",
    "    c=0\n",
    "    for k in range(12,16):\n",
    "        p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[3]\n",
    "        if (p_class_feature[k]>maxx):\n",
    "            maxx = p_class_feature[k]\n",
    "        p_class_feature1[3] = maxx\n",
    "        c=c+1\n",
    "    maxx=0\n",
    "    c=0\n",
    "    for k in range(16,20):\n",
    "        p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[4]\n",
    "        if (p_class_feature[k]>maxx):\n",
    "            maxx = p_class_feature[k]\n",
    "        p_class_feature1[4] = maxx\n",
    "        c=c+1\n",
    "    maxx=0\n",
    "    c=0\n",
    "    for k in range(20,24):\n",
    "        p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[5]\n",
    "        if (p_class_feature[k]>maxx):\n",
    "            maxx = p_class_feature[k]\n",
    "        p_class_feature1[5] = maxx\n",
    "        c=c+1\n",
    "    maxx=0\n",
    "    c=0\n",
    "    for k in range(24,28):\n",
    "        p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[6]\n",
    "        if (p_class_feature[k]>maxx):\n",
    "            maxx = p_class_feature[k]\n",
    "        p_class_feature1[6] = maxx\n",
    "        c=c+1\n",
    "    maxx=0\n",
    "    c=0\n",
    "    for k in range(28,32):\n",
    "        p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[7]\n",
    "        if (p_class_feature[k]>maxx):\n",
    "            maxx = p_class_feature[k]\n",
    "        p_class_feature1[7] = maxx\n",
    "        c=c+1\n",
    "    maxx=0\n",
    "    c=0\n",
    "    for k in range(32,36):\n",
    "        p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[8]\n",
    "        if (p_class_feature[k]>maxx):\n",
    "            maxx = p_class_feature[k]\n",
    "        p_class_feature1[8] = maxx\n",
    "        c=c+1\n",
    "    maxx=0\n",
    "    c=0\n",
    "    for k in range(36,40):\n",
    "        p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[9]\n",
    "        if (p_class_feature[k]>maxx):\n",
    "            maxx = p_class_feature[k]\n",
    "        p_class_feature1[9] = maxx\n",
    "        c=c+1\n",
    "    maxx=0\n",
    "    c=0\n",
    "    for k in range(40,44):\n",
    "        p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[10]\n",
    "        if (p_class_feature[k]>maxx):\n",
    "            maxx = p_class_feature[k]\n",
    "        p_class_feature1[10] = maxx\n",
    "        c=c+1\n",
    "    maxx=0\n",
    "    c=0\n",
    "    for k in range(44,48):\n",
    "        p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[11]\n",
    "        if (p_class_feature[k]>maxx):\n",
    "            maxx = p_class_feature[k]\n",
    "        p_class_feature1[11] = maxx\n",
    "        c=c+1\n",
    "    maxx=0\n",
    "    c=0\n",
    "    for k in range(48,52):\n",
    "        p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[12]\n",
    "        if (p_class_feature[k]>maxx):\n",
    "            maxx = p_class_feature[k]\n",
    "        p_class_feature1[12] = maxx\n",
    "        c=c+1\n",
    "    maxx=0\n",
    "    c=0\n",
    "    for k in range(52,56):\n",
    "        p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[13]\n",
    "        if (p_class_feature[k]>maxx):\n",
    "            maxx = p_class_feature[k]\n",
    "        p_class_feature1[13] = maxx\n",
    "        c=c+1\n",
    "    maxx=0\n",
    "    c=0\n",
    "    for k in range(56,60):\n",
    "        p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[14]\n",
    "        if (p_class_feature[k]>maxx):\n",
    "            maxx = p_class_feature[k]\n",
    "        p_class_feature1[14] = maxx\n",
    "        c=c+1\n",
    "    maxx=0\n",
    "    c=0\n",
    "    for k in range(60,64):\n",
    "        p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[15]\n",
    "        if (p_class_feature[k]>maxx):\n",
    "            maxx = p_class_feature[k]\n",
    "        p_class_feature1[15] = maxx\n",
    "        c=c+1\n",
    "    maxx=0\n",
    "    c=0\n",
    "    for k in range(64,68):\n",
    "        p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[16]\n",
    "        if (p_class_feature[k]>maxx):\n",
    "            maxx = p_class_feature[k]\n",
    "        p_class_feature1[16] = maxx\n",
    "        c=c+1\n",
    "    maxx=0\n",
    "    c=0\n",
    "    for k in range(68,72):\n",
    "        p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[17]\n",
    "        if (p_class_feature[k]>maxx):\n",
    "            maxx = p_class_feature[k]\n",
    "        p_class_feature1[17] = maxx\n",
    "        c=c+1\n",
    "    maxx=0\n",
    "    c=0\n",
    "    for k in range(72,76):\n",
    "        p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[18]\n",
    "        if (p_class_feature[k]>maxx):\n",
    "            maxx = p_class_feature[k]\n",
    "        p_class_feature1[18] = maxx\n",
    "        c=c+1\n",
    "    maxx=0\n",
    "    c=0\n",
    "    for k in range(76,80):\n",
    "        p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[19]\n",
    "        if (p_class_feature[k]>maxx):\n",
    "            maxx = p_class_feature[k]\n",
    "        p_class_feature1[19] = maxx\n",
    "        c=c+1\n",
    "    maxx=0\n",
    "    c=0\n",
    "    for k in range(80,84):\n",
    "        p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[20]\n",
    "        if (p_class_feature[k]>maxx):\n",
    "            maxx = p_class_feature[k]\n",
    "        p_class_feature1[20] = maxx\n",
    "        c=c+1\n",
    "    return p_class_feature1\n",
    "\n",
    "# A funcao a seguire retorna a probabilidade P(Ai|Vj)\n",
    "def probab_AiVj(dic_p_class_feature1):\n",
    "    p_class_feature1 = dic_p_class_feature1\n",
    "    maxx=0\n",
    "    p_Ai_Vj = {}\n",
    "    for i in range(0,4):\n",
    "        if (p_class_feature1[i]>maxx):\n",
    "            maxx=p_class_feature1[i]\n",
    "        p_Ai_Vj[0]=maxx\n",
    "    maxx=0\n",
    "    for i in range(4,8):\n",
    "        if (p_class_feature1[i]>maxx):\n",
    "            maxx=p_class_feature1[i]\n",
    "        p_Ai_Vj[1]=maxx\n",
    "    maxx=0\n",
    "    for i in range(8,12):\n",
    "        if (p_class_feature1[i]>maxx):\n",
    "            maxx=p_class_feature1[i]\n",
    "        p_Ai_Vj[2]=maxx\n",
    "    maxx=0\n",
    "    for i in range(12,15):\n",
    "        if (p_class_feature1[i]>maxx):\n",
    "            maxx=p_class_feature1[i]\n",
    "        p_Ai_Vj[3]=maxx\n",
    "    maxx=0\n",
    "    for i in range(15,18):\n",
    "        if (p_class_feature1[i]>maxx):\n",
    "            maxx=p_class_feature1[i]\n",
    "        p_Ai_Vj[4]=maxx\n",
    "    maxx=0\n",
    "    for i in range(18,21):\n",
    "        if (p_class_feature1[i]>maxx):\n",
    "            maxx=p_class_feature1[i]\n",
    "        p_Ai_Vj[5]=maxx\n",
    "    return p_Ai_Vj\n",
    "\n",
    "# A funcao a seguir retorna o Produtorio de P(Ai|Vj)\n",
    "def produtorio(dic_p_Ai_Vj):\n",
    "    p_Ai_Vj = dic_p_Ai_Vj\n",
    "    len_pAivJ=len(p_Ai_Vj)\n",
    "    produtorio=1\n",
    "    for i in range(0,len_pAivJ):\n",
    "        produtorio=(produtorio*p_Ai_Vj[i])\n",
    "    return produtorio\n",
    "\n",
    "# A funcao a seguir retorna a classe do carro de acordo com argmax(Pvj*produtorio)\n",
    "def define_classe(dic_p_class,produtorio):\n",
    "    p_class = dic_p_class\n",
    "    produtorio = produtorio\n",
    "    Pvj_Produtorio = {}\n",
    "    produto = 0\n",
    "    for i in range(0,4):\n",
    "        Pvj_Produtorio[i] = p_class[i]*produtorio\n",
    "        if (Pvj_Produtorio[i]>produto):\n",
    "            produto = Pvj_Produtorio[i]\n",
    "            Vnb = i\n",
    "    return Vnb\n",
    "\n",
    "\n",
    "# def main():\n",
    "#     filename=dataset\n",
    "#     nhae = separateByClass(filename)\n",
    "#     print(nhae)\n",
    "# if __name__ == \"__main__\":\n",
    "#     main()\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CLASSE:0\n"
     ]
    }
   ],
   "source": [
    "\n",
    "############################################## INICIO TESTE DE FUNCOES #####################################################\n",
    "\n",
    "class_element_v = dataset.classs.unique()\n",
    "separatedByClass = {}\n",
    "total_el_class = {}\n",
    "for i in range(0,4):\n",
    "    separatedByClass[i] = dataset.loc[(dataset['classs']==class_element_v[i])]\n",
    "    total_el_class[i] = separatedByClass[i]['classs'].count()\n",
    "\n",
    "data_columns = dataset.columns\n",
    "len_columns = len(data_columns)-1\n",
    "separatedByFeature = {}\n",
    "total_el_features = {}\n",
    "k=0\n",
    "for i in range(0,len_columns):\n",
    "    feature = dataset[data_columns[i]].unique() # Elementos de cada Feature\n",
    "    len_feature = len(feature)\n",
    "    for j in range(0,len_feature):\n",
    "        data_filter_feature = dataset.loc[(dataset[data_columns[i]] == feature[j])] \n",
    "        separatedByFeature[k] = data_filter_feature\n",
    "        total_el_features[k] = separatedByFeature[k][data_columns[i]].count()\n",
    "        k=k+1\n",
    "quant_el_features=len(total_el_features)\n",
    "\n",
    "len_dic = len(separatedByFeature)\n",
    "# data_columns = dataset.columns\n",
    "# len_columns = len(data_columns)-1\n",
    "separatedByFeatureClass = {}\n",
    "total_el_feature_class = {}\n",
    "k = 0\n",
    "for i in range (0,len_dic):\n",
    "    if (i>=0 and i<16):\n",
    "        data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[0])]\n",
    "        separatedByFeatureClass[k] = data_filter_feature_class\n",
    "        total_el_feature_class[k] = separatedByFeatureClass[k]['buying'].count()\n",
    "        k=k+1\n",
    "        data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[1])]\n",
    "        separatedByFeatureClass[k] = data_filter_feature_class\n",
    "        total_el_feature_class[k] = separatedByFeatureClass[k]['buying'].count()\n",
    "        k=k+1\n",
    "        data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[2])]\n",
    "        separatedByFeatureClass[k] = data_filter_feature_class\n",
    "        total_el_feature_class[k] = separatedByFeatureClass[k]['buying'].count()\n",
    "        k=k+1\n",
    "        data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[3])]\n",
    "        separatedByFeatureClass[k] = data_filter_feature_class\n",
    "        total_el_feature_class[k] = separatedByFeatureClass[k]['buying'].count()\n",
    "        k=k+1\n",
    "    elif (i>=16 and i<32):\n",
    "        data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[0])]\n",
    "        separatedByFeatureClass[k] = data_filter_feature_class\n",
    "        total_el_feature_class[k] = separatedByFeatureClass[k]['maint'].count()\n",
    "        k=k+1\n",
    "        data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[1])]\n",
    "        separatedByFeatureClass[k] = data_filter_feature_class\n",
    "        total_el_feature_class[k] = separatedByFeatureClass[k]['maint'].count()\n",
    "        k=k+1\n",
    "        data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[2])]\n",
    "        separatedByFeatureClass[k] = data_filter_feature_class\n",
    "        total_el_feature_class[k] = separatedByFeatureClass[k]['maint'].count()\n",
    "        k=k+1\n",
    "        data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[3])]\n",
    "        separatedByFeatureClass[k] = data_filter_feature_class\n",
    "        total_el_feature_class[k] = separatedByFeatureClass[k]['maint'].count()\n",
    "        k=k+1\n",
    "    elif (i>=32 and i<48):\n",
    "#         print(k)\n",
    "        data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[0])]\n",
    "        separatedByFeatureClass[k] = data_filter_feature_class\n",
    "        total_el_feature_class[k] = separatedByFeatureClass[k]['doors'].count()\n",
    "        k=k+1\n",
    "        data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[1])]\n",
    "        separatedByFeatureClass[k] = data_filter_feature_class\n",
    "        total_el_feature_class[k] = separatedByFeatureClass[k]['doors'].count()\n",
    "        k=k+1\n",
    "        data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[2])]\n",
    "        separatedByFeatureClass[k] = data_filter_feature_class\n",
    "        total_el_feature_class[k] = separatedByFeatureClass[k]['doors'].count()\n",
    "        k=k+1\n",
    "        data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[3])]\n",
    "        separatedByFeatureClass[k] = data_filter_feature_class\n",
    "        total_el_feature_class[k] = separatedByFeatureClass[k]['doors'].count()\n",
    "        k=k+1\n",
    "    elif (i>=48 and i<60):\n",
    "        data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[0])]\n",
    "        separatedByFeatureClass[k] = data_filter_feature_class\n",
    "        total_el_feature_class[k] = separatedByFeatureClass[k]['persons'].count()\n",
    "        k=k+1\n",
    "        data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[1])]\n",
    "        separatedByFeatureClass[k] = data_filter_feature_class\n",
    "        total_el_feature_class[k] = separatedByFeatureClass[k]['persons'].count()\n",
    "        k=k+1\n",
    "        data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[2])]\n",
    "        separatedByFeatureClass[k] = data_filter_feature_class\n",
    "        total_el_feature_class[k] = separatedByFeatureClass[k]['persons'].count()\n",
    "        k=k+1\n",
    "        data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[3])]\n",
    "        separatedByFeatureClass[k] = data_filter_feature_class\n",
    "        total_el_feature_class[k] = separatedByFeatureClass[k]['persons'].count()\n",
    "        k=k+1\n",
    "    elif (i>=60 and i<72):\n",
    "        data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[0])]\n",
    "        separatedByFeatureClass[k] = data_filter_feature_class\n",
    "        total_el_feature_class[k] = separatedByFeatureClass[k]['lug_boot'].count()\n",
    "        k=k+1\n",
    "        data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[1])]\n",
    "        separatedByFeatureClass[k] = data_filter_feature_class\n",
    "        total_el_feature_class[k] = separatedByFeatureClass[k]['lug_boot'].count()\n",
    "        k=k+1\n",
    "        data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[2])]\n",
    "        separatedByFeatureClass[k] = data_filter_feature_class\n",
    "        total_el_feature_class[k] = separatedByFeatureClass[k]['lug_boot'].count()\n",
    "        k=k+1\n",
    "        data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[3])]\n",
    "        separatedByFeatureClass[k] = data_filter_feature_class\n",
    "        total_el_feature_class[k] = separatedByFeatureClass[k]['lug_boot'].count()\n",
    "        k=k+1\n",
    "    elif (i>=72 and i<len_dic):\n",
    "        data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[0])]\n",
    "        separatedByFeatureClass[k] = data_filter_feature_class\n",
    "        total_el_feature_class[k] = separatedByFeatureClass[k]['lug_boot'].count()\n",
    "        k=k+1\n",
    "        data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[1])]\n",
    "        separatedByFeatureClass[k] = data_filter_feature_class\n",
    "        total_el_feature_class[k] = separatedByFeatureClass[k]['lug_boot'].count()\n",
    "        k=k+1\n",
    "        data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[2])]\n",
    "        separatedByFeatureClass[k] = data_filter_feature_class\n",
    "        total_el_feature_class[k] = separatedByFeatureClass[k]['lug_boot'].count()\n",
    "        k=k+1\n",
    "        data_filter_feature_class = separatedByFeature[i].loc[(separatedByFeature[i]['classs']==class_element_v[3])]\n",
    "        separatedByFeatureClass[k] = data_filter_feature_class\n",
    "        total_el_feature_class[k] = separatedByFeatureClass[k]['lug_boot'].count()\n",
    "        k=k+1\n",
    "\n",
    "p_feature_class = {}\n",
    "p_max_feature_class = {}\n",
    "k=0\n",
    "while (k>=0 and k<16):\n",
    "    p_feature_class[k] = total_el_feature_class[k]/total_el_class[0]\n",
    "    k=k+1\n",
    "    p_feature_class[k] = total_el_feature_class[k]/total_el_class[1]\n",
    "    k=k+1\n",
    "    p_feature_class[k] = total_el_feature_class[k]/total_el_class[2]\n",
    "    k=k+1\n",
    "    p_feature_class[k] = total_el_feature_class[k]/total_el_class[3]\n",
    "    k=k+1\n",
    "while (k>=16 and k<32):\n",
    "    p_feature_class[k] = total_el_feature_class[k]/total_el_class[0]\n",
    "    k=k+1\n",
    "    p_feature_class[k] = total_el_feature_class[k]/total_el_class[1]\n",
    "    k=k+1\n",
    "    p_feature_class[k] = total_el_feature_class[k]/total_el_class[2]\n",
    "    k=k+1\n",
    "    p_feature_class[k] = total_el_feature_class[k]/total_el_class[3]\n",
    "    k=k+1   \n",
    "while (k>=32 and k<48):\n",
    "    p_feature_class[k] = total_el_feature_class[k]/total_el_class[0]\n",
    "    k=k+1\n",
    "    p_feature_class[k] = total_el_feature_class[k]/total_el_class[1]\n",
    "    k=k+1\n",
    "    p_feature_class[k] = total_el_feature_class[k]/total_el_class[2]\n",
    "    k=k+1\n",
    "    p_feature_class[k] = total_el_feature_class[k]/total_el_class[3]\n",
    "    k=k+1  \n",
    "while (k>=48 and k<60):\n",
    "    p_feature_class[k] = total_el_feature_class[k]/total_el_class[0]\n",
    "    k=k+1\n",
    "    p_feature_class[k] = total_el_feature_class[k]/total_el_class[1]\n",
    "    k=k+1\n",
    "    p_feature_class[k] = total_el_feature_class[k]/total_el_class[2]\n",
    "    k=k+1\n",
    "    p_feature_class[k] = total_el_feature_class[k]/total_el_class[3]\n",
    "    k=k+1 \n",
    "while (k>=60 and k<72):\n",
    "    p_feature_class[k] = total_el_feature_class[k]/total_el_class[0]\n",
    "    k=k+1\n",
    "    p_feature_class[k] = total_el_feature_class[k]/total_el_class[1]\n",
    "    k=k+1\n",
    "    p_feature_class[k] = total_el_feature_class[k]/total_el_class[2]\n",
    "    k=k+1\n",
    "    p_feature_class[k] = total_el_feature_class[k]/total_el_class[3]\n",
    "    k=k+1 \n",
    "while (k>=72 and k<84):\n",
    "    p_feature_class[k] = total_el_feature_class[k]/total_el_class[0]\n",
    "    k=k+1\n",
    "    p_feature_class[k] = total_el_feature_class[k]/total_el_class[1]\n",
    "    k=k+1\n",
    "    p_feature_class[k] = total_el_feature_class[k]/total_el_class[2]\n",
    "    k=k+1\n",
    "    p_feature_class[k] = total_el_feature_class[k]/total_el_class[3]\n",
    "    k=k+1 \n",
    "# print(total_el_feature_class,k)\n",
    "\n",
    "p_feature = {}\n",
    "len_features = len(total_el_features)\n",
    "total_elements=0\n",
    "for i in range (0,4):\n",
    "    total_elements = total_elements+total_el_features[i]\n",
    "\n",
    "for i in range(0,len_features):\n",
    "    p_feature[i] = total_el_features[i]/total_elements\n",
    "\n",
    "# print(total_el_features)\n",
    "\n",
    "\n",
    "p_class = {}\n",
    "len_class = len(total_el_class)\n",
    "total_elements=0\n",
    "for i in range (0,4):\n",
    "    total_elements = total_elements+total_el_class[i]\n",
    "\n",
    "for i in range(0,len_class):\n",
    "    p_class[i] = total_el_class[i]/total_elements\n",
    "\n",
    "p_class_feature = {}\n",
    "p_class_feature1 = {}\n",
    "maxx=0\n",
    "c=0\n",
    "for k in range(0,4):\n",
    "    p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[0]\n",
    "    if (p_class_feature[k]>maxx):\n",
    "        maxx = p_class_feature[k]\n",
    "    p_class_feature1[0] = maxx\n",
    "    c=c+1\n",
    "\n",
    "maxx=0\n",
    "c=0\n",
    "for k in range(4,8):\n",
    "    p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[1]\n",
    "    if (p_class_feature[k]>maxx):\n",
    "        maxx = p_class_feature[k]\n",
    "    p_class_feature1[1] = maxx\n",
    "    c=c+1\n",
    "\n",
    "maxx=0\n",
    "c=0\n",
    "for k in range(8,12):\n",
    "    p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[2]\n",
    "    if (p_class_feature[k]>maxx):\n",
    "        maxx = p_class_feature[k]\n",
    "    p_class_feature1[2] = maxx\n",
    "    c=c+1\n",
    "maxx=0\n",
    "c=0\n",
    "for k in range(12,16):\n",
    "    p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[3]\n",
    "    if (p_class_feature[k]>maxx):\n",
    "        maxx = p_class_feature[k]\n",
    "    p_class_feature1[3] = maxx\n",
    "    c=c+1\n",
    "maxx=0\n",
    "c=0\n",
    "for k in range(16,20):\n",
    "    p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[4]\n",
    "    if (p_class_feature[k]>maxx):\n",
    "        maxx = p_class_feature[k]\n",
    "    p_class_feature1[4] = maxx\n",
    "    c=c+1\n",
    "maxx=0\n",
    "c=0\n",
    "for k in range(20,24):\n",
    "    p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[5]\n",
    "    if (p_class_feature[k]>maxx):\n",
    "        maxx = p_class_feature[k]\n",
    "    p_class_feature1[5] = maxx\n",
    "    c=c+1\n",
    "maxx=0\n",
    "c=0\n",
    "for k in range(24,28):\n",
    "    p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[6]\n",
    "    if (p_class_feature[k]>maxx):\n",
    "        maxx = p_class_feature[k]\n",
    "    p_class_feature1[6] = maxx\n",
    "    c=c+1\n",
    "maxx=0\n",
    "c=0\n",
    "for k in range(28,32):\n",
    "    p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[7]\n",
    "    if (p_class_feature[k]>maxx):\n",
    "        maxx = p_class_feature[k]\n",
    "    p_class_feature1[7] = maxx\n",
    "    c=c+1\n",
    "maxx=0\n",
    "c=0\n",
    "for k in range(32,36):\n",
    "    p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[8]\n",
    "    if (p_class_feature[k]>maxx):\n",
    "        maxx = p_class_feature[k]\n",
    "    p_class_feature1[8] = maxx\n",
    "    c=c+1\n",
    "maxx=0\n",
    "c=0\n",
    "for k in range(36,40):\n",
    "    p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[9]\n",
    "    if (p_class_feature[k]>maxx):\n",
    "        maxx = p_class_feature[k]\n",
    "    p_class_feature1[9] = maxx\n",
    "    c=c+1\n",
    "maxx=0\n",
    "c=0\n",
    "for k in range(40,44):\n",
    "    p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[10]\n",
    "    if (p_class_feature[k]>maxx):\n",
    "        maxx = p_class_feature[k]\n",
    "    p_class_feature1[10] = maxx\n",
    "    c=c+1\n",
    "maxx=0\n",
    "c=0\n",
    "for k in range(44,48):\n",
    "    p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[11]\n",
    "    if (p_class_feature[k]>maxx):\n",
    "        maxx = p_class_feature[k]\n",
    "    p_class_feature1[11] = maxx\n",
    "    c=c+1\n",
    "maxx=0\n",
    "c=0\n",
    "for k in range(48,52):\n",
    "    p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[12]\n",
    "    if (p_class_feature[k]>maxx):\n",
    "        maxx = p_class_feature[k]\n",
    "    p_class_feature1[12] = maxx\n",
    "    c=c+1\n",
    "maxx=0\n",
    "c=0\n",
    "for k in range(52,56):\n",
    "    p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[13]\n",
    "    if (p_class_feature[k]>maxx):\n",
    "        maxx = p_class_feature[k]\n",
    "    p_class_feature1[13] = maxx\n",
    "    c=c+1\n",
    "maxx=0\n",
    "c=0\n",
    "for k in range(56,60):\n",
    "    p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[14]\n",
    "    if (p_class_feature[k]>maxx):\n",
    "        maxx = p_class_feature[k]\n",
    "    p_class_feature1[14] = maxx\n",
    "    c=c+1\n",
    "maxx=0\n",
    "c=0\n",
    "for k in range(60,64):\n",
    "    p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[15]\n",
    "    if (p_class_feature[k]>maxx):\n",
    "        maxx = p_class_feature[k]\n",
    "    p_class_feature1[15] = maxx\n",
    "    c=c+1\n",
    "maxx=0\n",
    "c=0\n",
    "for k in range(64,68):\n",
    "    p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[16]\n",
    "    if (p_class_feature[k]>maxx):\n",
    "        maxx = p_class_feature[k]\n",
    "    p_class_feature1[16] = maxx\n",
    "    c=c+1\n",
    "maxx=0\n",
    "c=0\n",
    "for k in range(68,72):\n",
    "    p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[17]\n",
    "    if (p_class_feature[k]>maxx):\n",
    "        maxx = p_class_feature[k]\n",
    "    p_class_feature1[17] = maxx\n",
    "    c=c+1\n",
    "maxx=0\n",
    "c=0\n",
    "for k in range(72,76):\n",
    "    p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[18]\n",
    "    if (p_class_feature[k]>maxx):\n",
    "        maxx = p_class_feature[k]\n",
    "    p_class_feature1[18] = maxx\n",
    "    c=c+1\n",
    "maxx=0\n",
    "c=0\n",
    "for k in range(76,80):\n",
    "    p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[19]\n",
    "    if (p_class_feature[k]>maxx):\n",
    "        maxx = p_class_feature[k]\n",
    "    p_class_feature1[19] = maxx\n",
    "    c=c+1\n",
    "maxx=0\n",
    "c=0\n",
    "for k in range(80,84):\n",
    "    p_class_feature[k] = (p_feature_class[k]*p_class[c])/p_feature[20]\n",
    "    if (p_class_feature[k]>maxx):\n",
    "        maxx = p_class_feature[k]\n",
    "    p_class_feature1[20] = maxx\n",
    "    c=c+1\n",
    "    \n",
    "# print(p_class_feature1,quant_el_features)\n",
    "\n",
    "maxx=0\n",
    "p_Ai_Vj = {}\n",
    "for i in range(0,4):\n",
    "    if (p_class_feature1[i]>maxx):\n",
    "        maxx=p_class_feature1[i]\n",
    "    p_Ai_Vj[0]=maxx\n",
    "maxx=0\n",
    "for i in range(4,8):\n",
    "    if (p_class_feature1[i]>maxx):\n",
    "        maxx=p_class_feature1[i]\n",
    "    p_Ai_Vj[1]=maxx\n",
    "maxx=0\n",
    "for i in range(8,12):\n",
    "    if (p_class_feature1[i]>maxx):\n",
    "        maxx=p_class_feature1[i]\n",
    "    p_Ai_Vj[2]=maxx\n",
    "maxx=0\n",
    "for i in range(12,15):\n",
    "    if (p_class_feature1[i]>maxx):\n",
    "        maxx=p_class_feature1[i]\n",
    "    p_Ai_Vj[3]=maxx\n",
    "maxx=0\n",
    "for i in range(15,18):\n",
    "    if (p_class_feature1[i]>maxx):\n",
    "        maxx=p_class_feature1[i]\n",
    "    p_Ai_Vj[4]=maxx\n",
    "maxx=0\n",
    "for i in range(18,21):\n",
    "    if (p_class_feature1[i]>maxx):\n",
    "        maxx=p_class_feature1[i]\n",
    "    p_Ai_Vj[5]=maxx\n",
    "\n",
    "    \n",
    "len_pAivJ=len(p_Ai_Vj)\n",
    "produtorio=1\n",
    "for i in range(0,len_pAivJ):\n",
    "    produtorio=(produtorio*p_Ai_Vj[i])\n",
    "\n",
    "#argmax(Pvj*produtorio)\n",
    "Pvj_Produtorio = {}\n",
    "produto = 0\n",
    "for i in range(0,4):\n",
    "    Pvj_Produtorio[i] = p_class[i]*produtorio\n",
    "    if (Pvj_Produtorio[i]>produto):\n",
    "        produto = Pvj_Produtorio[i]\n",
    "        Vnb = i\n",
    "\n",
    "print(\"CLASSE:{0}\".format(classe))\n",
    "\n",
    "\n",
    "# A classe '0' representa a classe Unacess. Logo, a medida que novos valores (carros) são adicionados ao dataset\n",
    "# o algoritmo se encarrega de classifica-la entre as quatro classes disponíveis (uncess, acess, vgood, good)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "Modelo 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import csv\n",
    "import math\n",
    "import random\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    " \n",
    "def loadCsv(filename):\n",
    "    lines = csv.reader(open(filename, \"r\"))\n",
    "    dataset = list(lines)\n",
    "    for i in range(len(dataset)):\n",
    "        dataset[i] = [str(x) for x in dataset[i]]\n",
    "    return dataset    \n",
    "\n",
    "def splitDataset(dataset, splitRatio):\n",
    "    trainSize = int(len(dataset) * splitRatio)\n",
    "    trainSet = []\n",
    "    copy = list(dataset)\n",
    "    \n",
    "    while len(trainSet) < trainSize:\n",
    "        index = random.randrange(len(copy))\n",
    "        trainSet.append(copy.pop(index))\n",
    "    return [trainSet, copy]\n",
    "\n",
    "def separateByClass(dataset):\n",
    "    separated = {}\n",
    "    for i in range(len(dataset)):\n",
    "        vector = dataset[i]\n",
    "        if (vector[-1] not in separated):\n",
    "            separated[vector[-1]] = []\n",
    "        separated[vector[-1]].append(vector)\n",
    "    return separated\n",
    "\n",
    "def mean(numbers):\n",
    "    return sum(numbers)/float(len(numbers))\n",
    " \n",
    "def stdev(numbers):\n",
    "    avg = mean(numbers)\n",
    "    variance = sum([pow(x-avg,2) for x in numbers])/float(len(numbers)-1)\n",
    "    return math.sqrt(variance)\n",
    "\n",
    "def summarize(dataset):\n",
    "    summaries = [(mean(attribute), stdev(attribute)) for attribute in zip(*dataset)]\n",
    "    del summaries[-1]\n",
    "    #for attribute in zip(*dataset):\n",
    "    #    print(attribute)\n",
    "    return summaries\n",
    "\n",
    "def summarizeByClass(dataset):\n",
    "    separated = separateByClass(dataset)\n",
    "    summaries = {}\n",
    "    for classValue, instances in separated.items():\n",
    "        summaries[classValue] = summarize(instances)\n",
    "    return summaries\n",
    "\n",
    "def calculateProbability(x, mean, stdev):\n",
    "    if(stdev==0):\n",
    "        return 0\n",
    "    exponent = math.exp(-(math.pow(x-mean,2)/(2*math.pow(stdev,2))))\n",
    "    return (1 / (math.sqrt(2*math.pi * math.pow(stdev,2))) * exponent)\n",
    "\n",
    "def calculateClassProbabilities(summaries, inputVector):\n",
    "    probabilities = {}\n",
    "    for classValue, classSummaries in summaries.items():\n",
    "        probabilities[classValue] = 1\n",
    "        for i in range(len(classSummaries)):\n",
    "            mean, stdev = classSummaries[i]\n",
    "            x = inputVector[i]\n",
    "            probabilities[classValue] *= calculateProbability(x, mean, stdev)\n",
    "    return probabilities\n",
    "\n",
    "def predict(summaries, inputVector):\n",
    "    probabilities = calculateClassProbabilities(summaries, inputVector)\n",
    "    bestLabel, bestProb = None, -1\n",
    "    for classValue, probability in probabilities.items():\n",
    "        if bestLabel is None or probability > bestProb:\n",
    "            bestProb = probability\n",
    "            bestLabel = classValue\n",
    "    return bestLabel\n",
    "\n",
    "def getPredictions(summaries, testSet):\n",
    "    predictions = []\n",
    "    for i in range(len(testSet)):\n",
    "        result = predict(summaries, testSet[i])\n",
    "        predictions.append(result)\n",
    "    return predictions\n",
    "\n",
    "def getAccuracy(testSet, predictions):\n",
    "    correct = 0\n",
    "    for i in range(len(testSet)):\n",
    "        if testSet[i][-1] == predictions[i]:\n",
    "            correct += 1\n",
    "    return (correct/float(len(testSet))) * 100.0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Arquivo carregado car.data com 1728 linhas\n",
      "\n",
      "[[4 4 2 ..., 1 1 1]\n",
      " [4 4 2 ..., 1 2 1]\n",
      " [4 4 2 ..., 1 3 1]\n",
      " ..., \n",
      " [1 1 5 ..., 3 1 1]\n",
      " [1 1 5 ..., 3 2 3]\n",
      " [1 1 5 ..., 3 3 4]]\n",
      "dict_items([(1, [array([4, 4, 2, 2, 1, 1, 1]), array([4, 4, 2, 2, 1, 2, 1]), array([4, 4, 2, 2, 1, 3, 1]), array([4, 4, 2, 2, 2, 1, 1]), array([4, 4, 2, 2, 2, 2, 1]), array([4, 4, 2, 2, 2, 3, 1]), array([4, 4, 2, 2, 3, 1, 1]), array([4, 4, 2, 2, 3, 2, 1]), array([4, 4, 2, 2, 3, 3, 1]), array([4, 4, 2, 4, 1, 1, 1]), array([4, 4, 2, 4, 1, 2, 1]), array([4, 4, 2, 4, 1, 3, 1]), array([4, 4, 2, 4, 2, 1, 1]), array([4, 4, 2, 4, 2, 2, 1]), array([4, 4, 2, 4, 2, 3, 1]), array([4, 4, 2, 4, 3, 1, 1]), array([4, 4, 2, 4, 3, 2, 1]), array([4, 4, 2, 4, 3, 3, 1]), array([4, 4, 2, 5, 1, 1, 1]), array([4, 4, 2, 5, 1, 2, 1]), array([4, 4, 2, 5, 1, 3, 1]), array([4, 4, 2, 5, 2, 1, 1]), array([4, 4, 2, 5, 2, 2, 1]), array([4, 4, 2, 5, 2, 3, 1]), array([4, 4, 2, 5, 3, 1, 1]), array([4, 4, 2, 5, 3, 2, 1]), array([4, 4, 2, 5, 3, 3, 1]), array([4, 4, 3, 2, 1, 1, 1]), array([4, 4, 3, 2, 1, 2, 1]), array([4, 4, 3, 2, 1, 3, 1]), array([4, 4, 3, 2, 2, 1, 1]), array([4, 4, 3, 2, 2, 2, 1]), array([4, 4, 3, 2, 2, 3, 1]), array([4, 4, 3, 2, 3, 1, 1]), array([4, 4, 3, 2, 3, 2, 1]), array([4, 4, 3, 2, 3, 3, 1]), array([4, 4, 3, 4, 1, 1, 1]), array([4, 4, 3, 4, 1, 2, 1]), array([4, 4, 3, 4, 1, 3, 1]), array([4, 4, 3, 4, 2, 1, 1]), array([4, 4, 3, 4, 2, 2, 1]), array([4, 4, 3, 4, 2, 3, 1]), array([4, 4, 3, 4, 3, 1, 1]), array([4, 4, 3, 4, 3, 2, 1]), array([4, 4, 3, 4, 3, 3, 1]), array([4, 4, 3, 5, 1, 1, 1]), array([4, 4, 3, 5, 1, 2, 1]), array([4, 4, 3, 5, 1, 3, 1]), array([4, 4, 3, 5, 2, 1, 1]), array([4, 4, 3, 5, 2, 2, 1]), array([4, 4, 3, 5, 2, 3, 1]), array([4, 4, 3, 5, 3, 1, 1]), array([4, 4, 3, 5, 3, 2, 1]), array([4, 4, 3, 5, 3, 3, 1]), array([4, 4, 4, 2, 1, 1, 1]), array([4, 4, 4, 2, 1, 2, 1]), array([4, 4, 4, 2, 1, 3, 1]), array([4, 4, 4, 2, 2, 1, 1]), array([4, 4, 4, 2, 2, 2, 1]), array([4, 4, 4, 2, 2, 3, 1]), array([4, 4, 4, 2, 3, 1, 1]), array([4, 4, 4, 2, 3, 2, 1]), array([4, 4, 4, 2, 3, 3, 1]), array([4, 4, 4, 4, 1, 1, 1]), array([4, 4, 4, 4, 1, 2, 1]), array([4, 4, 4, 4, 1, 3, 1]), array([4, 4, 4, 4, 2, 1, 1]), array([4, 4, 4, 4, 2, 2, 1]), array([4, 4, 4, 4, 2, 3, 1]), array([4, 4, 4, 4, 3, 1, 1]), array([4, 4, 4, 4, 3, 2, 1]), array([4, 4, 4, 4, 3, 3, 1]), array([4, 4, 4, 5, 1, 1, 1]), array([4, 4, 4, 5, 1, 2, 1]), array([4, 4, 4, 5, 1, 3, 1]), array([4, 4, 4, 5, 2, 1, 1]), array([4, 4, 4, 5, 2, 2, 1]), array([4, 4, 4, 5, 2, 3, 1]), array([4, 4, 4, 5, 3, 1, 1]), array([4, 4, 4, 5, 3, 2, 1]), array([4, 4, 4, 5, 3, 3, 1]), array([4, 4, 5, 2, 1, 1, 1]), array([4, 4, 5, 2, 1, 2, 1]), array([4, 4, 5, 2, 1, 3, 1]), array([4, 4, 5, 2, 2, 1, 1]), array([4, 4, 5, 2, 2, 2, 1]), array([4, 4, 5, 2, 2, 3, 1]), array([4, 4, 5, 2, 3, 1, 1]), array([4, 4, 5, 2, 3, 2, 1]), array([4, 4, 5, 2, 3, 3, 1]), array([4, 4, 5, 4, 1, 1, 1]), array([4, 4, 5, 4, 1, 2, 1]), array([4, 4, 5, 4, 1, 3, 1]), array([4, 4, 5, 4, 2, 1, 1]), array([4, 4, 5, 4, 2, 2, 1]), array([4, 4, 5, 4, 2, 3, 1]), array([4, 4, 5, 4, 3, 1, 1]), array([4, 4, 5, 4, 3, 2, 1]), array([4, 4, 5, 4, 3, 3, 1]), array([4, 4, 5, 5, 1, 1, 1]), array([4, 4, 5, 5, 1, 2, 1]), array([4, 4, 5, 5, 1, 3, 1]), array([4, 4, 5, 5, 2, 1, 1]), array([4, 4, 5, 5, 2, 2, 1]), array([4, 4, 5, 5, 2, 3, 1]), array([4, 4, 5, 5, 3, 1, 1]), array([4, 4, 5, 5, 3, 2, 1]), array([4, 4, 5, 5, 3, 3, 1]), array([4, 3, 2, 2, 1, 1, 1]), array([4, 3, 2, 2, 1, 2, 1]), array([4, 3, 2, 2, 1, 3, 1]), array([4, 3, 2, 2, 2, 1, 1]), array([4, 3, 2, 2, 2, 2, 1]), array([4, 3, 2, 2, 2, 3, 1]), array([4, 3, 2, 2, 3, 1, 1]), array([4, 3, 2, 2, 3, 2, 1]), array([4, 3, 2, 2, 3, 3, 1]), array([4, 3, 2, 4, 1, 1, 1]), array([4, 3, 2, 4, 1, 2, 1]), array([4, 3, 2, 4, 1, 3, 1]), array([4, 3, 2, 4, 2, 1, 1]), array([4, 3, 2, 4, 2, 2, 1]), array([4, 3, 2, 4, 2, 3, 1]), array([4, 3, 2, 4, 3, 1, 1]), array([4, 3, 2, 4, 3, 2, 1]), array([4, 3, 2, 4, 3, 3, 1]), array([4, 3, 2, 5, 1, 1, 1]), array([4, 3, 2, 5, 1, 2, 1]), array([4, 3, 2, 5, 1, 3, 1]), array([4, 3, 2, 5, 2, 1, 1]), array([4, 3, 2, 5, 2, 2, 1]), array([4, 3, 2, 5, 2, 3, 1]), array([4, 3, 2, 5, 3, 1, 1]), array([4, 3, 2, 5, 3, 2, 1]), array([4, 3, 2, 5, 3, 3, 1]), array([4, 3, 3, 2, 1, 1, 1]), array([4, 3, 3, 2, 1, 2, 1]), array([4, 3, 3, 2, 1, 3, 1]), array([4, 3, 3, 2, 2, 1, 1]), array([4, 3, 3, 2, 2, 2, 1]), array([4, 3, 3, 2, 2, 3, 1]), array([4, 3, 3, 2, 3, 1, 1]), array([4, 3, 3, 2, 3, 2, 1]), array([4, 3, 3, 2, 3, 3, 1]), array([4, 3, 3, 4, 1, 1, 1]), array([4, 3, 3, 4, 1, 2, 1]), array([4, 3, 3, 4, 1, 3, 1]), array([4, 3, 3, 4, 2, 1, 1]), array([4, 3, 3, 4, 2, 2, 1]), array([4, 3, 3, 4, 2, 3, 1]), array([4, 3, 3, 4, 3, 1, 1]), array([4, 3, 3, 4, 3, 2, 1]), array([4, 3, 3, 4, 3, 3, 1]), array([4, 3, 3, 5, 1, 1, 1]), array([4, 3, 3, 5, 1, 2, 1]), array([4, 3, 3, 5, 1, 3, 1]), array([4, 3, 3, 5, 2, 1, 1]), array([4, 3, 3, 5, 2, 2, 1]), array([4, 3, 3, 5, 2, 3, 1]), array([4, 3, 3, 5, 3, 1, 1]), array([4, 3, 3, 5, 3, 2, 1]), array([4, 3, 3, 5, 3, 3, 1]), array([4, 3, 4, 2, 1, 1, 1]), array([4, 3, 4, 2, 1, 2, 1]), array([4, 3, 4, 2, 1, 3, 1]), array([4, 3, 4, 2, 2, 1, 1]), array([4, 3, 4, 2, 2, 2, 1]), array([4, 3, 4, 2, 2, 3, 1]), array([4, 3, 4, 2, 3, 1, 1]), array([4, 3, 4, 2, 3, 2, 1]), array([4, 3, 4, 2, 3, 3, 1]), array([4, 3, 4, 4, 1, 1, 1]), array([4, 3, 4, 4, 1, 2, 1]), array([4, 3, 4, 4, 1, 3, 1]), array([4, 3, 4, 4, 2, 1, 1]), array([4, 3, 4, 4, 2, 2, 1]), array([4, 3, 4, 4, 2, 3, 1]), array([4, 3, 4, 4, 3, 1, 1]), array([4, 3, 4, 4, 3, 2, 1]), array([4, 3, 4, 4, 3, 3, 1]), array([4, 3, 4, 5, 1, 1, 1]), array([4, 3, 4, 5, 1, 2, 1]), array([4, 3, 4, 5, 1, 3, 1]), array([4, 3, 4, 5, 2, 1, 1]), array([4, 3, 4, 5, 2, 2, 1]), array([4, 3, 4, 5, 2, 3, 1]), array([4, 3, 4, 5, 3, 1, 1]), array([4, 3, 4, 5, 3, 2, 1]), array([4, 3, 4, 5, 3, 3, 1]), array([4, 3, 5, 2, 1, 1, 1]), array([4, 3, 5, 2, 1, 2, 1]), array([4, 3, 5, 2, 1, 3, 1]), array([4, 3, 5, 2, 2, 1, 1]), array([4, 3, 5, 2, 2, 2, 1]), array([4, 3, 5, 2, 2, 3, 1]), array([4, 3, 5, 2, 3, 1, 1]), array([4, 3, 5, 2, 3, 2, 1]), array([4, 3, 5, 2, 3, 3, 1]), array([4, 3, 5, 4, 1, 1, 1]), array([4, 3, 5, 4, 1, 2, 1]), array([4, 3, 5, 4, 1, 3, 1]), array([4, 3, 5, 4, 2, 1, 1]), array([4, 3, 5, 4, 2, 2, 1]), array([4, 3, 5, 4, 2, 3, 1]), array([4, 3, 5, 4, 3, 1, 1]), array([4, 3, 5, 4, 3, 2, 1]), array([4, 3, 5, 4, 3, 3, 1]), array([4, 3, 5, 5, 1, 1, 1]), array([4, 3, 5, 5, 1, 2, 1]), array([4, 3, 5, 5, 1, 3, 1]), array([4, 3, 5, 5, 2, 1, 1]), array([4, 3, 5, 5, 2, 2, 1]), array([4, 3, 5, 5, 2, 3, 1]), array([4, 3, 5, 5, 3, 1, 1]), array([4, 3, 5, 5, 3, 2, 1]), array([4, 3, 5, 5, 3, 3, 1]), array([4, 2, 2, 2, 1, 1, 1]), array([4, 2, 2, 2, 1, 2, 1]), array([4, 2, 2, 2, 1, 3, 1]), array([4, 2, 2, 2, 2, 1, 1]), array([4, 2, 2, 2, 2, 2, 1]), array([4, 2, 2, 2, 2, 3, 1]), array([4, 2, 2, 2, 3, 1, 1]), array([4, 2, 2, 2, 3, 2, 1]), array([4, 2, 2, 2, 3, 3, 1]), array([4, 2, 2, 4, 1, 1, 1]), array([4, 2, 2, 4, 1, 2, 1]), array([4, 2, 2, 4, 2, 1, 1]), array([4, 2, 2, 4, 2, 2, 1]), array([4, 2, 2, 4, 3, 1, 1]), array([4, 2, 2, 5, 1, 1, 1]), array([4, 2, 2, 5, 1, 2, 1]), array([4, 2, 2, 5, 1, 3, 1]), array([4, 2, 2, 5, 2, 1, 1]), array([4, 2, 2, 5, 2, 2, 1]), array([4, 2, 2, 5, 3, 1, 1]), array([4, 2, 3, 2, 1, 1, 1]), array([4, 2, 3, 2, 1, 2, 1]), array([4, 2, 3, 2, 1, 3, 1]), array([4, 2, 3, 2, 2, 1, 1]), array([4, 2, 3, 2, 2, 2, 1]), array([4, 2, 3, 2, 2, 3, 1]), array([4, 2, 3, 2, 3, 1, 1]), array([4, 2, 3, 2, 3, 2, 1]), array([4, 2, 3, 2, 3, 3, 1]), array([4, 2, 3, 4, 1, 1, 1]), array([4, 2, 3, 4, 1, 2, 1]), array([4, 2, 3, 4, 2, 1, 1]), array([4, 2, 3, 4, 2, 2, 1]), array([4, 2, 3, 4, 3, 1, 1]), array([4, 2, 3, 5, 1, 1, 1]), array([4, 2, 3, 5, 1, 2, 1]), array([4, 2, 3, 5, 2, 1, 1]), array([4, 2, 3, 5, 3, 1, 1]), array([4, 2, 4, 2, 1, 1, 1]), array([4, 2, 4, 2, 1, 2, 1]), array([4, 2, 4, 2, 1, 3, 1]), array([4, 2, 4, 2, 2, 1, 1]), array([4, 2, 4, 2, 2, 2, 1]), array([4, 2, 4, 2, 2, 3, 1]), array([4, 2, 4, 2, 3, 1, 1]), array([4, 2, 4, 2, 3, 2, 1]), array([4, 2, 4, 2, 3, 3, 1]), array([4, 2, 4, 4, 1, 1, 1]), array([4, 2, 4, 4, 1, 2, 1]), array([4, 2, 4, 4, 2, 1, 1]), array([4, 2, 4, 4, 3, 1, 1]), array([4, 2, 4, 5, 1, 1, 1]), array([4, 2, 4, 5, 1, 2, 1]), array([4, 2, 4, 5, 2, 1, 1]), array([4, 2, 4, 5, 3, 1, 1]), array([4, 2, 5, 2, 1, 1, 1]), array([4, 2, 5, 2, 1, 2, 1]), array([4, 2, 5, 2, 1, 3, 1]), array([4, 2, 5, 2, 2, 1, 1]), array([4, 2, 5, 2, 2, 2, 1]), array([4, 2, 5, 2, 2, 3, 1]), array([4, 2, 5, 2, 3, 1, 1]), array([4, 2, 5, 2, 3, 2, 1]), array([4, 2, 5, 2, 3, 3, 1]), array([4, 2, 5, 4, 1, 1, 1]), array([4, 2, 5, 4, 1, 2, 1]), array([4, 2, 5, 4, 2, 1, 1]), array([4, 2, 5, 4, 3, 1, 1]), array([4, 2, 5, 5, 1, 1, 1]), array([4, 2, 5, 5, 1, 2, 1]), array([4, 2, 5, 5, 2, 1, 1]), array([4, 2, 5, 5, 3, 1, 1]), array([4, 1, 2, 2, 1, 1, 1]), array([4, 1, 2, 2, 1, 2, 1]), array([4, 1, 2, 2, 1, 3, 1]), array([4, 1, 2, 2, 2, 1, 1]), array([4, 1, 2, 2, 2, 2, 1]), array([4, 1, 2, 2, 2, 3, 1]), array([4, 1, 2, 2, 3, 1, 1]), array([4, 1, 2, 2, 3, 2, 1]), array([4, 1, 2, 2, 3, 3, 1]), array([4, 1, 2, 4, 1, 1, 1]), array([4, 1, 2, 4, 1, 2, 1]), array([4, 1, 2, 4, 2, 1, 1]), array([4, 1, 2, 4, 2, 2, 1]), array([4, 1, 2, 4, 3, 1, 1]), array([4, 1, 2, 5, 1, 1, 1]), array([4, 1, 2, 5, 1, 2, 1]), array([4, 1, 2, 5, 1, 3, 1]), array([4, 1, 2, 5, 2, 1, 1]), array([4, 1, 2, 5, 2, 2, 1]), array([4, 1, 2, 5, 3, 1, 1]), array([4, 1, 3, 2, 1, 1, 1]), array([4, 1, 3, 2, 1, 2, 1]), array([4, 1, 3, 2, 1, 3, 1]), array([4, 1, 3, 2, 2, 1, 1]), array([4, 1, 3, 2, 2, 2, 1]), array([4, 1, 3, 2, 2, 3, 1]), array([4, 1, 3, 2, 3, 1, 1]), array([4, 1, 3, 2, 3, 2, 1]), array([4, 1, 3, 2, 3, 3, 1]), array([4, 1, 3, 4, 1, 1, 1]), array([4, 1, 3, 4, 1, 2, 1]), array([4, 1, 3, 4, 2, 1, 1]), array([4, 1, 3, 4, 2, 2, 1]), array([4, 1, 3, 4, 3, 1, 1]), array([4, 1, 3, 5, 1, 1, 1]), array([4, 1, 3, 5, 1, 2, 1]), array([4, 1, 3, 5, 2, 1, 1]), array([4, 1, 3, 5, 3, 1, 1]), array([4, 1, 4, 2, 1, 1, 1]), array([4, 1, 4, 2, 1, 2, 1]), array([4, 1, 4, 2, 1, 3, 1]), array([4, 1, 4, 2, 2, 1, 1]), array([4, 1, 4, 2, 2, 2, 1]), array([4, 1, 4, 2, 2, 3, 1]), array([4, 1, 4, 2, 3, 1, 1]), array([4, 1, 4, 2, 3, 2, 1]), array([4, 1, 4, 2, 3, 3, 1]), array([4, 1, 4, 4, 1, 1, 1]), array([4, 1, 4, 4, 1, 2, 1]), array([4, 1, 4, 4, 2, 1, 1]), array([4, 1, 4, 4, 3, 1, 1]), array([4, 1, 4, 5, 1, 1, 1]), array([4, 1, 4, 5, 1, 2, 1]), array([4, 1, 4, 5, 2, 1, 1]), array([4, 1, 4, 5, 3, 1, 1]), array([4, 1, 5, 2, 1, 1, 1]), array([4, 1, 5, 2, 1, 2, 1]), array([4, 1, 5, 2, 1, 3, 1]), array([4, 1, 5, 2, 2, 1, 1]), array([4, 1, 5, 2, 2, 2, 1]), array([4, 1, 5, 2, 2, 3, 1]), array([4, 1, 5, 2, 3, 1, 1]), array([4, 1, 5, 2, 3, 2, 1]), array([4, 1, 5, 2, 3, 3, 1]), array([4, 1, 5, 4, 1, 1, 1]), array([4, 1, 5, 4, 1, 2, 1]), array([4, 1, 5, 4, 2, 1, 1]), array([4, 1, 5, 4, 3, 1, 1]), array([4, 1, 5, 5, 1, 1, 1]), array([4, 1, 5, 5, 1, 2, 1]), array([4, 1, 5, 5, 2, 1, 1]), array([4, 1, 5, 5, 3, 1, 1]), array([3, 4, 2, 2, 1, 1, 1]), array([3, 4, 2, 2, 1, 2, 1]), array([3, 4, 2, 2, 1, 3, 1]), array([3, 4, 2, 2, 2, 1, 1]), array([3, 4, 2, 2, 2, 2, 1]), array([3, 4, 2, 2, 2, 3, 1]), array([3, 4, 2, 2, 3, 1, 1]), array([3, 4, 2, 2, 3, 2, 1]), array([3, 4, 2, 2, 3, 3, 1]), array([3, 4, 2, 4, 1, 1, 1]), array([3, 4, 2, 4, 1, 2, 1]), array([3, 4, 2, 4, 1, 3, 1]), array([3, 4, 2, 4, 2, 1, 1]), array([3, 4, 2, 4, 2, 2, 1]), array([3, 4, 2, 4, 2, 3, 1]), array([3, 4, 2, 4, 3, 1, 1]), array([3, 4, 2, 4, 3, 2, 1]), array([3, 4, 2, 4, 3, 3, 1]), array([3, 4, 2, 5, 1, 1, 1]), array([3, 4, 2, 5, 1, 2, 1]), array([3, 4, 2, 5, 1, 3, 1]), array([3, 4, 2, 5, 2, 1, 1]), array([3, 4, 2, 5, 2, 2, 1]), array([3, 4, 2, 5, 2, 3, 1]), array([3, 4, 2, 5, 3, 1, 1]), array([3, 4, 2, 5, 3, 2, 1]), array([3, 4, 2, 5, 3, 3, 1]), array([3, 4, 3, 2, 1, 1, 1]), array([3, 4, 3, 2, 1, 2, 1]), array([3, 4, 3, 2, 1, 3, 1]), array([3, 4, 3, 2, 2, 1, 1]), array([3, 4, 3, 2, 2, 2, 1]), array([3, 4, 3, 2, 2, 3, 1]), array([3, 4, 3, 2, 3, 1, 1]), array([3, 4, 3, 2, 3, 2, 1]), array([3, 4, 3, 2, 3, 3, 1]), array([3, 4, 3, 4, 1, 1, 1]), array([3, 4, 3, 4, 1, 2, 1]), array([3, 4, 3, 4, 1, 3, 1]), array([3, 4, 3, 4, 2, 1, 1]), array([3, 4, 3, 4, 2, 2, 1]), array([3, 4, 3, 4, 2, 3, 1]), array([3, 4, 3, 4, 3, 1, 1]), array([3, 4, 3, 4, 3, 2, 1]), array([3, 4, 3, 4, 3, 3, 1]), array([3, 4, 3, 5, 1, 1, 1]), array([3, 4, 3, 5, 1, 2, 1]), array([3, 4, 3, 5, 1, 3, 1]), array([3, 4, 3, 5, 2, 1, 1]), array([3, 4, 3, 5, 2, 2, 1]), array([3, 4, 3, 5, 2, 3, 1]), array([3, 4, 3, 5, 3, 1, 1]), array([3, 4, 3, 5, 3, 2, 1]), array([3, 4, 3, 5, 3, 3, 1]), array([3, 4, 4, 2, 1, 1, 1]), array([3, 4, 4, 2, 1, 2, 1]), array([3, 4, 4, 2, 1, 3, 1]), array([3, 4, 4, 2, 2, 1, 1]), array([3, 4, 4, 2, 2, 2, 1]), array([3, 4, 4, 2, 2, 3, 1]), array([3, 4, 4, 2, 3, 1, 1]), array([3, 4, 4, 2, 3, 2, 1]), array([3, 4, 4, 2, 3, 3, 1]), array([3, 4, 4, 4, 1, 1, 1]), array([3, 4, 4, 4, 1, 2, 1]), array([3, 4, 4, 4, 1, 3, 1]), array([3, 4, 4, 4, 2, 1, 1]), array([3, 4, 4, 4, 2, 2, 1]), array([3, 4, 4, 4, 2, 3, 1]), array([3, 4, 4, 4, 3, 1, 1]), array([3, 4, 4, 4, 3, 2, 1]), array([3, 4, 4, 4, 3, 3, 1]), array([3, 4, 4, 5, 1, 1, 1]), array([3, 4, 4, 5, 1, 2, 1]), array([3, 4, 4, 5, 1, 3, 1]), array([3, 4, 4, 5, 2, 1, 1]), array([3, 4, 4, 5, 2, 2, 1]), array([3, 4, 4, 5, 2, 3, 1]), array([3, 4, 4, 5, 3, 1, 1]), array([3, 4, 4, 5, 3, 2, 1]), array([3, 4, 4, 5, 3, 3, 1]), array([3, 4, 5, 2, 1, 1, 1]), array([3, 4, 5, 2, 1, 2, 1]), array([3, 4, 5, 2, 1, 3, 1]), array([3, 4, 5, 2, 2, 1, 1]), array([3, 4, 5, 2, 2, 2, 1]), array([3, 4, 5, 2, 2, 3, 1]), array([3, 4, 5, 2, 3, 1, 1]), array([3, 4, 5, 2, 3, 2, 1]), array([3, 4, 5, 2, 3, 3, 1]), array([3, 4, 5, 4, 1, 1, 1]), array([3, 4, 5, 4, 1, 2, 1]), array([3, 4, 5, 4, 1, 3, 1]), array([3, 4, 5, 4, 2, 1, 1]), array([3, 4, 5, 4, 2, 2, 1]), array([3, 4, 5, 4, 2, 3, 1]), array([3, 4, 5, 4, 3, 1, 1]), array([3, 4, 5, 4, 3, 2, 1]), array([3, 4, 5, 4, 3, 3, 1]), array([3, 4, 5, 5, 1, 1, 1]), array([3, 4, 5, 5, 1, 2, 1]), array([3, 4, 5, 5, 1, 3, 1]), array([3, 4, 5, 5, 2, 1, 1]), array([3, 4, 5, 5, 2, 2, 1]), array([3, 4, 5, 5, 2, 3, 1]), array([3, 4, 5, 5, 3, 1, 1]), array([3, 4, 5, 5, 3, 2, 1]), array([3, 4, 5, 5, 3, 3, 1]), array([3, 3, 2, 2, 1, 1, 1]), array([3, 3, 2, 2, 1, 2, 1]), array([3, 3, 2, 2, 1, 3, 1]), array([3, 3, 2, 2, 2, 1, 1]), array([3, 3, 2, 2, 2, 2, 1]), array([3, 3, 2, 2, 2, 3, 1]), array([3, 3, 2, 2, 3, 1, 1]), array([3, 3, 2, 2, 3, 2, 1]), array([3, 3, 2, 2, 3, 3, 1]), array([3, 3, 2, 4, 1, 1, 1]), array([3, 3, 2, 4, 1, 2, 1]), array([3, 3, 2, 4, 2, 1, 1]), array([3, 3, 2, 4, 2, 2, 1]), array([3, 3, 2, 4, 3, 1, 1]), array([3, 3, 2, 5, 1, 1, 1]), array([3, 3, 2, 5, 1, 2, 1]), array([3, 3, 2, 5, 1, 3, 1]), array([3, 3, 2, 5, 2, 1, 1]), array([3, 3, 2, 5, 2, 2, 1]), array([3, 3, 2, 5, 3, 1, 1]), array([3, 3, 3, 2, 1, 1, 1]), array([3, 3, 3, 2, 1, 2, 1]), array([3, 3, 3, 2, 1, 3, 1]), array([3, 3, 3, 2, 2, 1, 1]), array([3, 3, 3, 2, 2, 2, 1]), array([3, 3, 3, 2, 2, 3, 1]), array([3, 3, 3, 2, 3, 1, 1]), array([3, 3, 3, 2, 3, 2, 1]), array([3, 3, 3, 2, 3, 3, 1]), array([3, 3, 3, 4, 1, 1, 1]), array([3, 3, 3, 4, 1, 2, 1]), array([3, 3, 3, 4, 2, 1, 1]), array([3, 3, 3, 4, 2, 2, 1]), array([3, 3, 3, 4, 3, 1, 1]), array([3, 3, 3, 5, 1, 1, 1]), array([3, 3, 3, 5, 1, 2, 1]), array([3, 3, 3, 5, 2, 1, 1]), array([3, 3, 3, 5, 3, 1, 1]), array([3, 3, 4, 2, 1, 1, 1]), array([3, 3, 4, 2, 1, 2, 1]), array([3, 3, 4, 2, 1, 3, 1]), array([3, 3, 4, 2, 2, 1, 1]), array([3, 3, 4, 2, 2, 2, 1]), array([3, 3, 4, 2, 2, 3, 1]), array([3, 3, 4, 2, 3, 1, 1]), array([3, 3, 4, 2, 3, 2, 1]), array([3, 3, 4, 2, 3, 3, 1]), array([3, 3, 4, 4, 1, 1, 1]), array([3, 3, 4, 4, 1, 2, 1]), array([3, 3, 4, 4, 2, 1, 1]), array([3, 3, 4, 4, 3, 1, 1]), array([3, 3, 4, 5, 1, 1, 1]), array([3, 3, 4, 5, 1, 2, 1]), array([3, 3, 4, 5, 2, 1, 1]), array([3, 3, 4, 5, 3, 1, 1]), array([3, 3, 5, 2, 1, 1, 1]), array([3, 3, 5, 2, 1, 2, 1]), array([3, 3, 5, 2, 1, 3, 1]), array([3, 3, 5, 2, 2, 1, 1]), array([3, 3, 5, 2, 2, 2, 1]), array([3, 3, 5, 2, 2, 3, 1]), array([3, 3, 5, 2, 3, 1, 1]), array([3, 3, 5, 2, 3, 2, 1]), array([3, 3, 5, 2, 3, 3, 1]), array([3, 3, 5, 4, 1, 1, 1]), array([3, 3, 5, 4, 1, 2, 1]), array([3, 3, 5, 4, 2, 1, 1]), array([3, 3, 5, 4, 3, 1, 1]), array([3, 3, 5, 5, 1, 1, 1]), array([3, 3, 5, 5, 1, 2, 1]), array([3, 3, 5, 5, 2, 1, 1]), array([3, 3, 5, 5, 3, 1, 1]), array([3, 2, 2, 2, 1, 1, 1]), array([3, 2, 2, 2, 1, 2, 1]), array([3, 2, 2, 2, 1, 3, 1]), array([3, 2, 2, 2, 2, 1, 1]), array([3, 2, 2, 2, 2, 2, 1]), array([3, 2, 2, 2, 2, 3, 1]), array([3, 2, 2, 2, 3, 1, 1]), array([3, 2, 2, 2, 3, 2, 1]), array([3, 2, 2, 2, 3, 3, 1]), array([3, 2, 2, 4, 1, 1, 1]), array([3, 2, 2, 4, 1, 2, 1]), array([3, 2, 2, 4, 2, 1, 1]), array([3, 2, 2, 4, 2, 2, 1]), array([3, 2, 2, 4, 3, 1, 1]), array([3, 2, 2, 5, 1, 1, 1]), array([3, 2, 2, 5, 1, 2, 1]), array([3, 2, 2, 5, 1, 3, 1]), array([3, 2, 2, 5, 2, 1, 1]), array([3, 2, 2, 5, 2, 2, 1]), array([3, 2, 2, 5, 3, 1, 1]), array([3, 2, 3, 2, 1, 1, 1]), array([3, 2, 3, 2, 1, 2, 1]), array([3, 2, 3, 2, 1, 3, 1]), array([3, 2, 3, 2, 2, 1, 1]), array([3, 2, 3, 2, 2, 2, 1]), array([3, 2, 3, 2, 2, 3, 1]), array([3, 2, 3, 2, 3, 1, 1]), array([3, 2, 3, 2, 3, 2, 1]), array([3, 2, 3, 2, 3, 3, 1]), array([3, 2, 3, 4, 1, 1, 1]), array([3, 2, 3, 4, 1, 2, 1]), array([3, 2, 3, 4, 2, 1, 1]), array([3, 2, 3, 4, 2, 2, 1]), array([3, 2, 3, 4, 3, 1, 1]), array([3, 2, 3, 5, 1, 1, 1]), array([3, 2, 3, 5, 1, 2, 1]), array([3, 2, 3, 5, 2, 1, 1]), array([3, 2, 3, 5, 3, 1, 1]), array([3, 2, 4, 2, 1, 1, 1]), array([3, 2, 4, 2, 1, 2, 1]), array([3, 2, 4, 2, 1, 3, 1]), array([3, 2, 4, 2, 2, 1, 1]), array([3, 2, 4, 2, 2, 2, 1]), array([3, 2, 4, 2, 2, 3, 1]), array([3, 2, 4, 2, 3, 1, 1]), array([3, 2, 4, 2, 3, 2, 1]), array([3, 2, 4, 2, 3, 3, 1]), array([3, 2, 4, 4, 1, 1, 1]), array([3, 2, 4, 4, 1, 2, 1]), array([3, 2, 4, 4, 2, 1, 1]), array([3, 2, 4, 4, 3, 1, 1]), array([3, 2, 4, 5, 1, 1, 1]), array([3, 2, 4, 5, 1, 2, 1]), array([3, 2, 4, 5, 2, 1, 1]), array([3, 2, 4, 5, 3, 1, 1]), array([3, 2, 5, 2, 1, 1, 1]), array([3, 2, 5, 2, 1, 2, 1]), array([3, 2, 5, 2, 1, 3, 1]), array([3, 2, 5, 2, 2, 1, 1]), array([3, 2, 5, 2, 2, 2, 1]), array([3, 2, 5, 2, 2, 3, 1]), array([3, 2, 5, 2, 3, 1, 1]), array([3, 2, 5, 2, 3, 2, 1]), array([3, 2, 5, 2, 3, 3, 1]), array([3, 2, 5, 4, 1, 1, 1]), array([3, 2, 5, 4, 1, 2, 1]), array([3, 2, 5, 4, 2, 1, 1]), array([3, 2, 5, 4, 3, 1, 1]), array([3, 2, 5, 5, 1, 1, 1]), array([3, 2, 5, 5, 1, 2, 1]), array([3, 2, 5, 5, 2, 1, 1]), array([3, 2, 5, 5, 3, 1, 1]), array([3, 1, 2, 2, 1, 1, 1]), array([3, 1, 2, 2, 1, 2, 1]), array([3, 1, 2, 2, 1, 3, 1]), array([3, 1, 2, 2, 2, 1, 1]), array([3, 1, 2, 2, 2, 2, 1]), array([3, 1, 2, 2, 2, 3, 1]), array([3, 1, 2, 2, 3, 1, 1]), array([3, 1, 2, 2, 3, 2, 1]), array([3, 1, 2, 2, 3, 3, 1]), array([3, 1, 2, 4, 1, 1, 1]), array([3, 1, 2, 4, 1, 2, 1]), array([3, 1, 2, 4, 2, 1, 1]), array([3, 1, 2, 4, 2, 2, 1]), array([3, 1, 2, 4, 3, 1, 1]), array([3, 1, 2, 5, 1, 1, 1]), array([3, 1, 2, 5, 1, 2, 1]), array([3, 1, 2, 5, 1, 3, 1]), array([3, 1, 2, 5, 2, 1, 1]), array([3, 1, 2, 5, 2, 2, 1]), array([3, 1, 2, 5, 3, 1, 1]), array([3, 1, 3, 2, 1, 1, 1]), array([3, 1, 3, 2, 1, 2, 1]), array([3, 1, 3, 2, 1, 3, 1]), array([3, 1, 3, 2, 2, 1, 1]), array([3, 1, 3, 2, 2, 2, 1]), array([3, 1, 3, 2, 2, 3, 1]), array([3, 1, 3, 2, 3, 1, 1]), array([3, 1, 3, 2, 3, 2, 1]), array([3, 1, 3, 2, 3, 3, 1]), array([3, 1, 3, 4, 1, 1, 1]), array([3, 1, 3, 4, 1, 2, 1]), array([3, 1, 3, 4, 2, 1, 1]), array([3, 1, 3, 4, 2, 2, 1]), array([3, 1, 3, 4, 3, 1, 1]), array([3, 1, 3, 5, 1, 1, 1]), array([3, 1, 3, 5, 1, 2, 1]), array([3, 1, 3, 5, 2, 1, 1]), array([3, 1, 3, 5, 3, 1, 1]), array([3, 1, 4, 2, 1, 1, 1]), array([3, 1, 4, 2, 1, 2, 1]), array([3, 1, 4, 2, 1, 3, 1]), array([3, 1, 4, 2, 2, 1, 1]), array([3, 1, 4, 2, 2, 2, 1]), array([3, 1, 4, 2, 2, 3, 1]), array([3, 1, 4, 2, 3, 1, 1]), array([3, 1, 4, 2, 3, 2, 1]), array([3, 1, 4, 2, 3, 3, 1]), array([3, 1, 4, 4, 1, 1, 1]), array([3, 1, 4, 4, 1, 2, 1]), array([3, 1, 4, 4, 2, 1, 1]), array([3, 1, 4, 4, 3, 1, 1]), array([3, 1, 4, 5, 1, 1, 1]), array([3, 1, 4, 5, 1, 2, 1]), array([3, 1, 4, 5, 2, 1, 1]), array([3, 1, 4, 5, 3, 1, 1]), array([3, 1, 5, 2, 1, 1, 1]), array([3, 1, 5, 2, 1, 2, 1]), array([3, 1, 5, 2, 1, 3, 1]), array([3, 1, 5, 2, 2, 1, 1]), array([3, 1, 5, 2, 2, 2, 1]), array([3, 1, 5, 2, 2, 3, 1]), array([3, 1, 5, 2, 3, 1, 1]), array([3, 1, 5, 2, 3, 2, 1]), array([3, 1, 5, 2, 3, 3, 1]), array([3, 1, 5, 4, 1, 1, 1]), array([3, 1, 5, 4, 1, 2, 1]), array([3, 1, 5, 4, 2, 1, 1]), array([3, 1, 5, 4, 3, 1, 1]), array([3, 1, 5, 5, 1, 1, 1]), array([3, 1, 5, 5, 1, 2, 1]), array([3, 1, 5, 5, 2, 1, 1]), array([3, 1, 5, 5, 3, 1, 1]), array([2, 4, 2, 2, 1, 1, 1]), array([2, 4, 2, 2, 1, 2, 1]), array([2, 4, 2, 2, 1, 3, 1]), array([2, 4, 2, 2, 2, 1, 1]), array([2, 4, 2, 2, 2, 2, 1]), array([2, 4, 2, 2, 2, 3, 1]), array([2, 4, 2, 2, 3, 1, 1]), array([2, 4, 2, 2, 3, 2, 1]), array([2, 4, 2, 2, 3, 3, 1]), array([2, 4, 2, 4, 1, 1, 1]), array([2, 4, 2, 4, 1, 2, 1]), array([2, 4, 2, 4, 2, 1, 1]), array([2, 4, 2, 4, 2, 2, 1]), array([2, 4, 2, 4, 3, 1, 1]), array([2, 4, 2, 5, 1, 1, 1]), array([2, 4, 2, 5, 1, 2, 1]), array([2, 4, 2, 5, 1, 3, 1]), array([2, 4, 2, 5, 2, 1, 1]), array([2, 4, 2, 5, 2, 2, 1]), array([2, 4, 2, 5, 3, 1, 1]), array([2, 4, 3, 2, 1, 1, 1]), array([2, 4, 3, 2, 1, 2, 1]), array([2, 4, 3, 2, 1, 3, 1]), array([2, 4, 3, 2, 2, 1, 1]), array([2, 4, 3, 2, 2, 2, 1]), array([2, 4, 3, 2, 2, 3, 1]), array([2, 4, 3, 2, 3, 1, 1]), array([2, 4, 3, 2, 3, 2, 1]), array([2, 4, 3, 2, 3, 3, 1]), array([2, 4, 3, 4, 1, 1, 1]), array([2, 4, 3, 4, 1, 2, 1]), array([2, 4, 3, 4, 2, 1, 1]), array([2, 4, 3, 4, 2, 2, 1]), array([2, 4, 3, 4, 3, 1, 1]), array([2, 4, 3, 5, 1, 1, 1]), array([2, 4, 3, 5, 1, 2, 1]), array([2, 4, 3, 5, 2, 1, 1]), array([2, 4, 3, 5, 3, 1, 1]), array([2, 4, 4, 2, 1, 1, 1]), array([2, 4, 4, 2, 1, 2, 1]), array([2, 4, 4, 2, 1, 3, 1]), array([2, 4, 4, 2, 2, 1, 1]), array([2, 4, 4, 2, 2, 2, 1]), array([2, 4, 4, 2, 2, 3, 1]), array([2, 4, 4, 2, 3, 1, 1]), array([2, 4, 4, 2, 3, 2, 1]), array([2, 4, 4, 2, 3, 3, 1]), array([2, 4, 4, 4, 1, 1, 1]), array([2, 4, 4, 4, 1, 2, 1]), array([2, 4, 4, 4, 2, 1, 1]), array([2, 4, 4, 4, 3, 1, 1]), array([2, 4, 4, 5, 1, 1, 1]), array([2, 4, 4, 5, 1, 2, 1]), array([2, 4, 4, 5, 2, 1, 1]), array([2, 4, 4, 5, 3, 1, 1]), array([2, 4, 5, 2, 1, 1, 1]), array([2, 4, 5, 2, 1, 2, 1]), array([2, 4, 5, 2, 1, 3, 1]), array([2, 4, 5, 2, 2, 1, 1]), array([2, 4, 5, 2, 2, 2, 1]), array([2, 4, 5, 2, 2, 3, 1]), array([2, 4, 5, 2, 3, 1, 1]), array([2, 4, 5, 2, 3, 2, 1]), array([2, 4, 5, 2, 3, 3, 1]), array([2, 4, 5, 4, 1, 1, 1]), array([2, 4, 5, 4, 1, 2, 1]), array([2, 4, 5, 4, 2, 1, 1]), array([2, 4, 5, 4, 3, 1, 1]), array([2, 4, 5, 5, 1, 1, 1]), array([2, 4, 5, 5, 1, 2, 1]), array([2, 4, 5, 5, 2, 1, 1]), array([2, 4, 5, 5, 3, 1, 1]), array([2, 3, 2, 2, 1, 1, 1]), array([2, 3, 2, 2, 1, 2, 1]), array([2, 3, 2, 2, 1, 3, 1]), array([2, 3, 2, 2, 2, 1, 1]), array([2, 3, 2, 2, 2, 2, 1]), array([2, 3, 2, 2, 2, 3, 1]), array([2, 3, 2, 2, 3, 1, 1]), array([2, 3, 2, 2, 3, 2, 1]), array([2, 3, 2, 2, 3, 3, 1]), array([2, 3, 2, 4, 1, 1, 1]), array([2, 3, 2, 4, 1, 2, 1]), array([2, 3, 2, 4, 2, 1, 1]), array([2, 3, 2, 4, 2, 2, 1]), array([2, 3, 2, 4, 3, 1, 1]), array([2, 3, 2, 5, 1, 1, 1]), array([2, 3, 2, 5, 1, 2, 1]), array([2, 3, 2, 5, 1, 3, 1]), array([2, 3, 2, 5, 2, 1, 1]), array([2, 3, 2, 5, 2, 2, 1]), array([2, 3, 2, 5, 3, 1, 1]), array([2, 3, 3, 2, 1, 1, 1]), array([2, 3, 3, 2, 1, 2, 1]), array([2, 3, 3, 2, 1, 3, 1]), array([2, 3, 3, 2, 2, 1, 1]), array([2, 3, 3, 2, 2, 2, 1]), array([2, 3, 3, 2, 2, 3, 1]), array([2, 3, 3, 2, 3, 1, 1]), array([2, 3, 3, 2, 3, 2, 1]), array([2, 3, 3, 2, 3, 3, 1]), array([2, 3, 3, 4, 1, 1, 1]), array([2, 3, 3, 4, 1, 2, 1]), array([2, 3, 3, 4, 2, 1, 1]), array([2, 3, 3, 4, 2, 2, 1]), array([2, 3, 3, 4, 3, 1, 1]), array([2, 3, 3, 5, 1, 1, 1]), array([2, 3, 3, 5, 1, 2, 1]), array([2, 3, 3, 5, 2, 1, 1]), array([2, 3, 3, 5, 3, 1, 1]), array([2, 3, 4, 2, 1, 1, 1]), array([2, 3, 4, 2, 1, 2, 1]), array([2, 3, 4, 2, 1, 3, 1]), array([2, 3, 4, 2, 2, 1, 1]), array([2, 3, 4, 2, 2, 2, 1]), array([2, 3, 4, 2, 2, 3, 1]), array([2, 3, 4, 2, 3, 1, 1]), array([2, 3, 4, 2, 3, 2, 1]), array([2, 3, 4, 2, 3, 3, 1]), array([2, 3, 4, 4, 1, 1, 1]), array([2, 3, 4, 4, 1, 2, 1]), array([2, 3, 4, 4, 2, 1, 1]), array([2, 3, 4, 4, 3, 1, 1]), array([2, 3, 4, 5, 1, 1, 1]), array([2, 3, 4, 5, 1, 2, 1]), array([2, 3, 4, 5, 2, 1, 1]), array([2, 3, 4, 5, 3, 1, 1]), array([2, 3, 5, 2, 1, 1, 1]), array([2, 3, 5, 2, 1, 2, 1]), array([2, 3, 5, 2, 1, 3, 1]), array([2, 3, 5, 2, 2, 1, 1]), array([2, 3, 5, 2, 2, 2, 1]), array([2, 3, 5, 2, 2, 3, 1]), array([2, 3, 5, 2, 3, 1, 1]), array([2, 3, 5, 2, 3, 2, 1]), array([2, 3, 5, 2, 3, 3, 1]), array([2, 3, 5, 4, 1, 1, 1]), array([2, 3, 5, 4, 1, 2, 1]), array([2, 3, 5, 4, 2, 1, 1]), array([2, 3, 5, 4, 3, 1, 1]), array([2, 3, 5, 5, 1, 1, 1]), array([2, 3, 5, 5, 1, 2, 1]), array([2, 3, 5, 5, 2, 1, 1]), array([2, 3, 5, 5, 3, 1, 1]), array([2, 2, 2, 2, 1, 1, 1]), array([2, 2, 2, 2, 1, 2, 1]), array([2, 2, 2, 2, 1, 3, 1]), array([2, 2, 2, 2, 2, 1, 1]), array([2, 2, 2, 2, 2, 2, 1]), array([2, 2, 2, 2, 2, 3, 1]), array([2, 2, 2, 2, 3, 1, 1]), array([2, 2, 2, 2, 3, 2, 1]), array([2, 2, 2, 2, 3, 3, 1]), array([2, 2, 2, 4, 1, 1, 1]), array([2, 2, 2, 4, 2, 1, 1]), array([2, 2, 2, 4, 3, 1, 1]), array([2, 2, 2, 5, 1, 1, 1]), array([2, 2, 2, 5, 1, 2, 1]), array([2, 2, 2, 5, 1, 3, 1]), array([2, 2, 2, 5, 2, 1, 1]), array([2, 2, 2, 5, 3, 1, 1]), array([2, 2, 3, 2, 1, 1, 1]), array([2, 2, 3, 2, 1, 2, 1]), array([2, 2, 3, 2, 1, 3, 1]), array([2, 2, 3, 2, 2, 1, 1]), array([2, 2, 3, 2, 2, 2, 1]), array([2, 2, 3, 2, 2, 3, 1]), array([2, 2, 3, 2, 3, 1, 1]), array([2, 2, 3, 2, 3, 2, 1]), array([2, 2, 3, 2, 3, 3, 1]), array([2, 2, 3, 4, 1, 1, 1]), array([2, 2, 3, 4, 2, 1, 1]), array([2, 2, 3, 4, 3, 1, 1]), array([2, 2, 3, 5, 1, 1, 1]), array([2, 2, 3, 5, 2, 1, 1]), array([2, 2, 3, 5, 3, 1, 1]), array([2, 2, 4, 2, 1, 1, 1]), array([2, 2, 4, 2, 1, 2, 1]), array([2, 2, 4, 2, 1, 3, 1]), array([2, 2, 4, 2, 2, 1, 1]), array([2, 2, 4, 2, 2, 2, 1]), array([2, 2, 4, 2, 2, 3, 1]), array([2, 2, 4, 2, 3, 1, 1]), array([2, 2, 4, 2, 3, 2, 1]), array([2, 2, 4, 2, 3, 3, 1]), array([2, 2, 4, 4, 1, 1, 1]), array([2, 2, 4, 4, 2, 1, 1]), array([2, 2, 4, 4, 3, 1, 1]), array([2, 2, 4, 5, 1, 1, 1]), array([2, 2, 4, 5, 2, 1, 1]), array([2, 2, 4, 5, 3, 1, 1]), array([2, 2, 5, 2, 1, 1, 1]), array([2, 2, 5, 2, 1, 2, 1]), array([2, 2, 5, 2, 1, 3, 1]), array([2, 2, 5, 2, 2, 1, 1]), array([2, 2, 5, 2, 2, 2, 1]), array([2, 2, 5, 2, 2, 3, 1]), array([2, 2, 5, 2, 3, 1, 1]), array([2, 2, 5, 2, 3, 2, 1]), array([2, 2, 5, 2, 3, 3, 1]), array([2, 2, 5, 4, 1, 1, 1]), array([2, 2, 5, 4, 2, 1, 1]), array([2, 2, 5, 4, 3, 1, 1]), array([2, 2, 5, 5, 1, 1, 1]), array([2, 2, 5, 5, 2, 1, 1]), array([2, 2, 5, 5, 3, 1, 1]), array([2, 1, 2, 2, 1, 1, 1]), array([2, 1, 2, 2, 1, 2, 1]), array([2, 1, 2, 2, 1, 3, 1]), array([2, 1, 2, 2, 2, 1, 1]), array([2, 1, 2, 2, 2, 2, 1]), array([2, 1, 2, 2, 2, 3, 1]), array([2, 1, 2, 2, 3, 1, 1]), array([2, 1, 2, 2, 3, 2, 1]), array([2, 1, 2, 2, 3, 3, 1]), array([2, 1, 2, 4, 1, 1, 1]), array([2, 1, 2, 4, 2, 1, 1]), array([2, 1, 2, 4, 3, 1, 1]), array([2, 1, 2, 5, 1, 1, 1]), array([2, 1, 2, 5, 1, 2, 1]), array([2, 1, 2, 5, 1, 3, 1]), array([2, 1, 2, 5, 2, 1, 1]), array([2, 1, 2, 5, 3, 1, 1]), array([2, 1, 3, 2, 1, 1, 1]), array([2, 1, 3, 2, 1, 2, 1]), array([2, 1, 3, 2, 1, 3, 1]), array([2, 1, 3, 2, 2, 1, 1]), array([2, 1, 3, 2, 2, 2, 1]), array([2, 1, 3, 2, 2, 3, 1]), array([2, 1, 3, 2, 3, 1, 1]), array([2, 1, 3, 2, 3, 2, 1]), array([2, 1, 3, 2, 3, 3, 1]), array([2, 1, 3, 4, 1, 1, 1]), array([2, 1, 3, 4, 2, 1, 1]), array([2, 1, 3, 4, 3, 1, 1]), array([2, 1, 3, 5, 1, 1, 1]), array([2, 1, 3, 5, 2, 1, 1]), array([2, 1, 3, 5, 3, 1, 1]), array([2, 1, 4, 2, 1, 1, 1]), array([2, 1, 4, 2, 1, 2, 1]), array([2, 1, 4, 2, 1, 3, 1]), array([2, 1, 4, 2, 2, 1, 1]), array([2, 1, 4, 2, 2, 2, 1]), array([2, 1, 4, 2, 2, 3, 1]), array([2, 1, 4, 2, 3, 1, 1]), array([2, 1, 4, 2, 3, 2, 1]), array([2, 1, 4, 2, 3, 3, 1]), array([2, 1, 4, 4, 1, 1, 1]), array([2, 1, 4, 4, 2, 1, 1]), array([2, 1, 4, 4, 3, 1, 1]), array([2, 1, 4, 5, 1, 1, 1]), array([2, 1, 4, 5, 2, 1, 1]), array([2, 1, 4, 5, 3, 1, 1]), array([2, 1, 5, 2, 1, 1, 1]), array([2, 1, 5, 2, 1, 2, 1]), array([2, 1, 5, 2, 1, 3, 1]), array([2, 1, 5, 2, 2, 1, 1]), array([2, 1, 5, 2, 2, 2, 1]), array([2, 1, 5, 2, 2, 3, 1]), array([2, 1, 5, 2, 3, 1, 1]), array([2, 1, 5, 2, 3, 2, 1]), array([2, 1, 5, 2, 3, 3, 1]), array([2, 1, 5, 4, 1, 1, 1]), array([2, 1, 5, 4, 2, 1, 1]), array([2, 1, 5, 4, 3, 1, 1]), array([2, 1, 5, 5, 1, 1, 1]), array([2, 1, 5, 5, 2, 1, 1]), array([2, 1, 5, 5, 3, 1, 1]), array([1, 4, 2, 2, 1, 1, 1]), array([1, 4, 2, 2, 1, 2, 1]), array([1, 4, 2, 2, 1, 3, 1]), array([1, 4, 2, 2, 2, 1, 1]), array([1, 4, 2, 2, 2, 2, 1]), array([1, 4, 2, 2, 2, 3, 1]), array([1, 4, 2, 2, 3, 1, 1]), array([1, 4, 2, 2, 3, 2, 1]), array([1, 4, 2, 2, 3, 3, 1]), array([1, 4, 2, 4, 1, 1, 1]), array([1, 4, 2, 4, 1, 2, 1]), array([1, 4, 2, 4, 2, 1, 1]), array([1, 4, 2, 4, 2, 2, 1]), array([1, 4, 2, 4, 3, 1, 1]), array([1, 4, 2, 5, 1, 1, 1]), array([1, 4, 2, 5, 1, 2, 1]), array([1, 4, 2, 5, 1, 3, 1]), array([1, 4, 2, 5, 2, 1, 1]), array([1, 4, 2, 5, 2, 2, 1]), array([1, 4, 2, 5, 3, 1, 1]), array([1, 4, 3, 2, 1, 1, 1]), array([1, 4, 3, 2, 1, 2, 1]), array([1, 4, 3, 2, 1, 3, 1]), array([1, 4, 3, 2, 2, 1, 1]), array([1, 4, 3, 2, 2, 2, 1]), array([1, 4, 3, 2, 2, 3, 1]), array([1, 4, 3, 2, 3, 1, 1]), array([1, 4, 3, 2, 3, 2, 1]), array([1, 4, 3, 2, 3, 3, 1]), array([1, 4, 3, 4, 1, 1, 1]), array([1, 4, 3, 4, 1, 2, 1]), array([1, 4, 3, 4, 2, 1, 1]), array([1, 4, 3, 4, 2, 2, 1]), array([1, 4, 3, 4, 3, 1, 1]), array([1, 4, 3, 5, 1, 1, 1]), array([1, 4, 3, 5, 1, 2, 1]), array([1, 4, 3, 5, 2, 1, 1]), array([1, 4, 3, 5, 3, 1, 1]), array([1, 4, 4, 2, 1, 1, 1]), array([1, 4, 4, 2, 1, 2, 1]), array([1, 4, 4, 2, 1, 3, 1]), array([1, 4, 4, 2, 2, 1, 1]), array([1, 4, 4, 2, 2, 2, 1]), array([1, 4, 4, 2, 2, 3, 1]), array([1, 4, 4, 2, 3, 1, 1]), array([1, 4, 4, 2, 3, 2, 1]), array([1, 4, 4, 2, 3, 3, 1]), array([1, 4, 4, 4, 1, 1, 1]), array([1, 4, 4, 4, 1, 2, 1]), array([1, 4, 4, 4, 2, 1, 1]), array([1, 4, 4, 4, 3, 1, 1]), array([1, 4, 4, 5, 1, 1, 1]), array([1, 4, 4, 5, 1, 2, 1]), array([1, 4, 4, 5, 2, 1, 1]), array([1, 4, 4, 5, 3, 1, 1]), array([1, 4, 5, 2, 1, 1, 1]), array([1, 4, 5, 2, 1, 2, 1]), array([1, 4, 5, 2, 1, 3, 1]), array([1, 4, 5, 2, 2, 1, 1]), array([1, 4, 5, 2, 2, 2, 1]), array([1, 4, 5, 2, 2, 3, 1]), array([1, 4, 5, 2, 3, 1, 1]), array([1, 4, 5, 2, 3, 2, 1]), array([1, 4, 5, 2, 3, 3, 1]), array([1, 4, 5, 4, 1, 1, 1]), array([1, 4, 5, 4, 1, 2, 1]), array([1, 4, 5, 4, 2, 1, 1]), array([1, 4, 5, 4, 3, 1, 1]), array([1, 4, 5, 5, 1, 1, 1]), array([1, 4, 5, 5, 1, 2, 1]), array([1, 4, 5, 5, 2, 1, 1]), array([1, 4, 5, 5, 3, 1, 1]), array([1, 3, 2, 2, 1, 1, 1]), array([1, 3, 2, 2, 1, 2, 1]), array([1, 3, 2, 2, 1, 3, 1]), array([1, 3, 2, 2, 2, 1, 1]), array([1, 3, 2, 2, 2, 2, 1]), array([1, 3, 2, 2, 2, 3, 1]), array([1, 3, 2, 2, 3, 1, 1]), array([1, 3, 2, 2, 3, 2, 1]), array([1, 3, 2, 2, 3, 3, 1]), array([1, 3, 2, 4, 1, 1, 1]), array([1, 3, 2, 4, 2, 1, 1]), array([1, 3, 2, 4, 3, 1, 1]), array([1, 3, 2, 5, 1, 1, 1]), array([1, 3, 2, 5, 1, 2, 1]), array([1, 3, 2, 5, 1, 3, 1]), array([1, 3, 2, 5, 2, 1, 1]), array([1, 3, 2, 5, 3, 1, 1]), array([1, 3, 3, 2, 1, 1, 1]), array([1, 3, 3, 2, 1, 2, 1]), array([1, 3, 3, 2, 1, 3, 1]), array([1, 3, 3, 2, 2, 1, 1]), array([1, 3, 3, 2, 2, 2, 1]), array([1, 3, 3, 2, 2, 3, 1]), array([1, 3, 3, 2, 3, 1, 1]), array([1, 3, 3, 2, 3, 2, 1]), array([1, 3, 3, 2, 3, 3, 1]), array([1, 3, 3, 4, 1, 1, 1]), array([1, 3, 3, 4, 2, 1, 1]), array([1, 3, 3, 4, 3, 1, 1]), array([1, 3, 3, 5, 1, 1, 1]), array([1, 3, 3, 5, 2, 1, 1]), array([1, 3, 3, 5, 3, 1, 1]), array([1, 3, 4, 2, 1, 1, 1]), array([1, 3, 4, 2, 1, 2, 1]), array([1, 3, 4, 2, 1, 3, 1]), array([1, 3, 4, 2, 2, 1, 1]), array([1, 3, 4, 2, 2, 2, 1]), array([1, 3, 4, 2, 2, 3, 1]), array([1, 3, 4, 2, 3, 1, 1]), array([1, 3, 4, 2, 3, 2, 1]), array([1, 3, 4, 2, 3, 3, 1]), array([1, 3, 4, 4, 1, 1, 1]), array([1, 3, 4, 4, 2, 1, 1]), array([1, 3, 4, 4, 3, 1, 1]), array([1, 3, 4, 5, 1, 1, 1]), array([1, 3, 4, 5, 2, 1, 1]), array([1, 3, 4, 5, 3, 1, 1]), array([1, 3, 5, 2, 1, 1, 1]), array([1, 3, 5, 2, 1, 2, 1]), array([1, 3, 5, 2, 1, 3, 1]), array([1, 3, 5, 2, 2, 1, 1]), array([1, 3, 5, 2, 2, 2, 1]), array([1, 3, 5, 2, 2, 3, 1]), array([1, 3, 5, 2, 3, 1, 1]), array([1, 3, 5, 2, 3, 2, 1]), array([1, 3, 5, 2, 3, 3, 1]), array([1, 3, 5, 4, 1, 1, 1]), array([1, 3, 5, 4, 2, 1, 1]), array([1, 3, 5, 4, 3, 1, 1]), array([1, 3, 5, 5, 1, 1, 1]), array([1, 3, 5, 5, 2, 1, 1]), array([1, 3, 5, 5, 3, 1, 1]), array([1, 2, 2, 2, 1, 1, 1]), array([1, 2, 2, 2, 1, 2, 1]), array([1, 2, 2, 2, 1, 3, 1]), array([1, 2, 2, 2, 2, 1, 1]), array([1, 2, 2, 2, 2, 2, 1]), array([1, 2, 2, 2, 2, 3, 1]), array([1, 2, 2, 2, 3, 1, 1]), array([1, 2, 2, 2, 3, 2, 1]), array([1, 2, 2, 2, 3, 3, 1]), array([1, 2, 2, 4, 1, 1, 1]), array([1, 2, 2, 4, 2, 1, 1]), array([1, 2, 2, 4, 3, 1, 1]), array([1, 2, 2, 5, 1, 1, 1]), array([1, 2, 2, 5, 1, 2, 1]), array([1, 2, 2, 5, 1, 3, 1]), array([1, 2, 2, 5, 2, 1, 1]), array([1, 2, 2, 5, 3, 1, 1]), array([1, 2, 3, 2, 1, 1, 1]), array([1, 2, 3, 2, 1, 2, 1]), array([1, 2, 3, 2, 1, 3, 1]), array([1, 2, 3, 2, 2, 1, 1]), array([1, 2, 3, 2, 2, 2, 1]), array([1, 2, 3, 2, 2, 3, 1]), array([1, 2, 3, 2, 3, 1, 1]), array([1, 2, 3, 2, 3, 2, 1]), array([1, 2, 3, 2, 3, 3, 1]), array([1, 2, 3, 4, 1, 1, 1]), array([1, 2, 3, 4, 2, 1, 1]), array([1, 2, 3, 4, 3, 1, 1]), array([1, 2, 3, 5, 1, 1, 1]), array([1, 2, 3, 5, 2, 1, 1]), array([1, 2, 3, 5, 3, 1, 1]), array([1, 2, 4, 2, 1, 1, 1]), array([1, 2, 4, 2, 1, 2, 1]), array([1, 2, 4, 2, 1, 3, 1]), array([1, 2, 4, 2, 2, 1, 1]), array([1, 2, 4, 2, 2, 2, 1]), array([1, 2, 4, 2, 2, 3, 1]), array([1, 2, 4, 2, 3, 1, 1]), array([1, 2, 4, 2, 3, 2, 1]), array([1, 2, 4, 2, 3, 3, 1]), array([1, 2, 4, 4, 1, 1, 1]), array([1, 2, 4, 4, 2, 1, 1]), array([1, 2, 4, 4, 3, 1, 1]), array([1, 2, 4, 5, 1, 1, 1]), array([1, 2, 4, 5, 2, 1, 1]), array([1, 2, 4, 5, 3, 1, 1]), array([1, 2, 5, 2, 1, 1, 1]), array([1, 2, 5, 2, 1, 2, 1]), array([1, 2, 5, 2, 1, 3, 1]), array([1, 2, 5, 2, 2, 1, 1]), array([1, 2, 5, 2, 2, 2, 1]), array([1, 2, 5, 2, 2, 3, 1]), array([1, 2, 5, 2, 3, 1, 1]), array([1, 2, 5, 2, 3, 2, 1]), array([1, 2, 5, 2, 3, 3, 1]), array([1, 2, 5, 4, 1, 1, 1]), array([1, 2, 5, 4, 2, 1, 1]), array([1, 2, 5, 4, 3, 1, 1]), array([1, 2, 5, 5, 1, 1, 1]), array([1, 2, 5, 5, 2, 1, 1]), array([1, 2, 5, 5, 3, 1, 1]), array([1, 1, 2, 2, 1, 1, 1]), array([1, 1, 2, 2, 1, 2, 1]), array([1, 1, 2, 2, 1, 3, 1]), array([1, 1, 2, 2, 2, 1, 1]), array([1, 1, 2, 2, 2, 2, 1]), array([1, 1, 2, 2, 2, 3, 1]), array([1, 1, 2, 2, 3, 1, 1]), array([1, 1, 2, 2, 3, 2, 1]), array([1, 1, 2, 2, 3, 3, 1]), array([1, 1, 2, 4, 1, 1, 1]), array([1, 1, 2, 4, 2, 1, 1]), array([1, 1, 2, 4, 3, 1, 1]), array([1, 1, 2, 5, 1, 1, 1]), array([1, 1, 2, 5, 1, 2, 1]), array([1, 1, 2, 5, 1, 3, 1]), array([1, 1, 2, 5, 2, 1, 1]), array([1, 1, 2, 5, 3, 1, 1]), array([1, 1, 3, 2, 1, 1, 1]), array([1, 1, 3, 2, 1, 2, 1]), array([1, 1, 3, 2, 1, 3, 1]), array([1, 1, 3, 2, 2, 1, 1]), array([1, 1, 3, 2, 2, 2, 1]), array([1, 1, 3, 2, 2, 3, 1]), array([1, 1, 3, 2, 3, 1, 1]), array([1, 1, 3, 2, 3, 2, 1]), array([1, 1, 3, 2, 3, 3, 1]), array([1, 1, 3, 4, 1, 1, 1]), array([1, 1, 3, 4, 2, 1, 1]), array([1, 1, 3, 4, 3, 1, 1]), array([1, 1, 3, 5, 1, 1, 1]), array([1, 1, 3, 5, 2, 1, 1]), array([1, 1, 3, 5, 3, 1, 1]), array([1, 1, 4, 2, 1, 1, 1]), array([1, 1, 4, 2, 1, 2, 1]), array([1, 1, 4, 2, 1, 3, 1]), array([1, 1, 4, 2, 2, 1, 1]), array([1, 1, 4, 2, 2, 2, 1]), array([1, 1, 4, 2, 2, 3, 1]), array([1, 1, 4, 2, 3, 1, 1]), array([1, 1, 4, 2, 3, 2, 1]), array([1, 1, 4, 2, 3, 3, 1]), array([1, 1, 4, 4, 1, 1, 1]), array([1, 1, 4, 4, 2, 1, 1]), array([1, 1, 4, 4, 3, 1, 1]), array([1, 1, 4, 5, 1, 1, 1]), array([1, 1, 4, 5, 2, 1, 1]), array([1, 1, 4, 5, 3, 1, 1]), array([1, 1, 5, 2, 1, 1, 1]), array([1, 1, 5, 2, 1, 2, 1]), array([1, 1, 5, 2, 1, 3, 1]), array([1, 1, 5, 2, 2, 1, 1]), array([1, 1, 5, 2, 2, 2, 1]), array([1, 1, 5, 2, 2, 3, 1]), array([1, 1, 5, 2, 3, 1, 1]), array([1, 1, 5, 2, 3, 2, 1]), array([1, 1, 5, 2, 3, 3, 1]), array([1, 1, 5, 4, 1, 1, 1]), array([1, 1, 5, 4, 2, 1, 1]), array([1, 1, 5, 4, 3, 1, 1]), array([1, 1, 5, 5, 1, 1, 1]), array([1, 1, 5, 5, 2, 1, 1]), array([1, 1, 5, 5, 3, 1, 1])]), (2, [array([4, 2, 2, 4, 1, 3, 2]), array([4, 2, 2, 4, 2, 3, 2]), array([4, 2, 2, 4, 3, 2, 2]), array([4, 2, 2, 4, 3, 3, 2]), array([4, 2, 2, 5, 2, 3, 2]), array([4, 2, 2, 5, 3, 2, 2]), array([4, 2, 2, 5, 3, 3, 2]), array([4, 2, 3, 4, 1, 3, 2]), array([4, 2, 3, 4, 2, 3, 2]), array([4, 2, 3, 4, 3, 2, 2]), array([4, 2, 3, 4, 3, 3, 2]), array([4, 2, 3, 5, 1, 3, 2]), array([4, 2, 3, 5, 2, 2, 2]), array([4, 2, 3, 5, 2, 3, 2]), array([4, 2, 3, 5, 3, 2, 2]), array([4, 2, 3, 5, 3, 3, 2]), array([4, 2, 4, 4, 1, 3, 2]), array([4, 2, 4, 4, 2, 2, 2]), array([4, 2, 4, 4, 2, 3, 2]), array([4, 2, 4, 4, 3, 2, 2]), array([4, 2, 4, 4, 3, 3, 2]), array([4, 2, 4, 5, 1, 3, 2]), array([4, 2, 4, 5, 2, 2, 2]), array([4, 2, 4, 5, 2, 3, 2]), array([4, 2, 4, 5, 3, 2, 2]), array([4, 2, 4, 5, 3, 3, 2]), array([4, 2, 5, 4, 1, 3, 2]), array([4, 2, 5, 4, 2, 2, 2]), array([4, 2, 5, 4, 2, 3, 2]), array([4, 2, 5, 4, 3, 2, 2]), array([4, 2, 5, 4, 3, 3, 2]), array([4, 2, 5, 5, 1, 3, 2]), array([4, 2, 5, 5, 2, 2, 2]), array([4, 2, 5, 5, 2, 3, 2]), array([4, 2, 5, 5, 3, 2, 2]), array([4, 2, 5, 5, 3, 3, 2]), array([4, 1, 2, 4, 1, 3, 2]), array([4, 1, 2, 4, 2, 3, 2]), array([4, 1, 2, 4, 3, 2, 2]), array([4, 1, 2, 4, 3, 3, 2]), array([4, 1, 2, 5, 2, 3, 2]), array([4, 1, 2, 5, 3, 2, 2]), array([4, 1, 2, 5, 3, 3, 2]), array([4, 1, 3, 4, 1, 3, 2]), array([4, 1, 3, 4, 2, 3, 2]), array([4, 1, 3, 4, 3, 2, 2]), array([4, 1, 3, 4, 3, 3, 2]), array([4, 1, 3, 5, 1, 3, 2]), array([4, 1, 3, 5, 2, 2, 2]), array([4, 1, 3, 5, 2, 3, 2]), array([4, 1, 3, 5, 3, 2, 2]), array([4, 1, 3, 5, 3, 3, 2]), array([4, 1, 4, 4, 1, 3, 2]), array([4, 1, 4, 4, 2, 2, 2]), array([4, 1, 4, 4, 2, 3, 2]), array([4, 1, 4, 4, 3, 2, 2]), array([4, 1, 4, 4, 3, 3, 2]), array([4, 1, 4, 5, 1, 3, 2]), array([4, 1, 4, 5, 2, 2, 2]), array([4, 1, 4, 5, 2, 3, 2]), array([4, 1, 4, 5, 3, 2, 2]), array([4, 1, 4, 5, 3, 3, 2]), array([4, 1, 5, 4, 1, 3, 2]), array([4, 1, 5, 4, 2, 2, 2]), array([4, 1, 5, 4, 2, 3, 2]), array([4, 1, 5, 4, 3, 2, 2]), array([4, 1, 5, 4, 3, 3, 2]), array([4, 1, 5, 5, 1, 3, 2]), array([4, 1, 5, 5, 2, 2, 2]), array([4, 1, 5, 5, 2, 3, 2]), array([4, 1, 5, 5, 3, 2, 2]), array([4, 1, 5, 5, 3, 3, 2]), array([3, 3, 2, 4, 1, 3, 2]), array([3, 3, 2, 4, 2, 3, 2]), array([3, 3, 2, 4, 3, 2, 2]), array([3, 3, 2, 4, 3, 3, 2]), array([3, 3, 2, 5, 2, 3, 2]), array([3, 3, 2, 5, 3, 2, 2]), array([3, 3, 2, 5, 3, 3, 2]), array([3, 3, 3, 4, 1, 3, 2]), array([3, 3, 3, 4, 2, 3, 2]), array([3, 3, 3, 4, 3, 2, 2]), array([3, 3, 3, 4, 3, 3, 2]), array([3, 3, 3, 5, 1, 3, 2]), array([3, 3, 3, 5, 2, 2, 2]), array([3, 3, 3, 5, 2, 3, 2]), array([3, 3, 3, 5, 3, 2, 2]), array([3, 3, 3, 5, 3, 3, 2]), array([3, 3, 4, 4, 1, 3, 2]), array([3, 3, 4, 4, 2, 2, 2]), array([3, 3, 4, 4, 2, 3, 2]), array([3, 3, 4, 4, 3, 2, 2]), array([3, 3, 4, 4, 3, 3, 2]), array([3, 3, 4, 5, 1, 3, 2]), array([3, 3, 4, 5, 2, 2, 2]), array([3, 3, 4, 5, 2, 3, 2]), array([3, 3, 4, 5, 3, 2, 2]), array([3, 3, 4, 5, 3, 3, 2]), array([3, 3, 5, 4, 1, 3, 2]), array([3, 3, 5, 4, 2, 2, 2]), array([3, 3, 5, 4, 2, 3, 2]), array([3, 3, 5, 4, 3, 2, 2]), array([3, 3, 5, 4, 3, 3, 2]), array([3, 3, 5, 5, 1, 3, 2]), array([3, 3, 5, 5, 2, 2, 2]), array([3, 3, 5, 5, 2, 3, 2]), array([3, 3, 5, 5, 3, 2, 2]), array([3, 3, 5, 5, 3, 3, 2]), array([3, 2, 2, 4, 1, 3, 2]), array([3, 2, 2, 4, 2, 3, 2]), array([3, 2, 2, 4, 3, 2, 2]), array([3, 2, 2, 4, 3, 3, 2]), array([3, 2, 2, 5, 2, 3, 2]), array([3, 2, 2, 5, 3, 2, 2]), array([3, 2, 2, 5, 3, 3, 2]), array([3, 2, 3, 4, 1, 3, 2]), array([3, 2, 3, 4, 2, 3, 2]), array([3, 2, 3, 4, 3, 2, 2]), array([3, 2, 3, 4, 3, 3, 2]), array([3, 2, 3, 5, 1, 3, 2]), array([3, 2, 3, 5, 2, 2, 2]), array([3, 2, 3, 5, 2, 3, 2]), array([3, 2, 3, 5, 3, 2, 2]), array([3, 2, 3, 5, 3, 3, 2]), array([3, 2, 4, 4, 1, 3, 2]), array([3, 2, 4, 4, 2, 2, 2]), array([3, 2, 4, 4, 2, 3, 2]), array([3, 2, 4, 4, 3, 2, 2]), array([3, 2, 4, 4, 3, 3, 2]), array([3, 2, 4, 5, 1, 3, 2]), array([3, 2, 4, 5, 2, 2, 2]), array([3, 2, 4, 5, 2, 3, 2]), array([3, 2, 4, 5, 3, 2, 2]), array([3, 2, 4, 5, 3, 3, 2]), array([3, 2, 5, 4, 1, 3, 2]), array([3, 2, 5, 4, 2, 2, 2]), array([3, 2, 5, 4, 2, 3, 2]), array([3, 2, 5, 4, 3, 2, 2]), array([3, 2, 5, 4, 3, 3, 2]), array([3, 2, 5, 5, 1, 3, 2]), array([3, 2, 5, 5, 2, 2, 2]), array([3, 2, 5, 5, 2, 3, 2]), array([3, 2, 5, 5, 3, 2, 2]), array([3, 2, 5, 5, 3, 3, 2]), array([3, 1, 2, 4, 1, 3, 2]), array([3, 1, 2, 4, 2, 3, 2]), array([3, 1, 2, 4, 3, 2, 2]), array([3, 1, 2, 4, 3, 3, 2]), array([3, 1, 2, 5, 2, 3, 2]), array([3, 1, 2, 5, 3, 2, 2]), array([3, 1, 2, 5, 3, 3, 2]), array([3, 1, 3, 4, 1, 3, 2]), array([3, 1, 3, 4, 2, 3, 2]), array([3, 1, 3, 4, 3, 2, 2]), array([3, 1, 3, 4, 3, 3, 2]), array([3, 1, 3, 5, 1, 3, 2]), array([3, 1, 3, 5, 2, 2, 2]), array([3, 1, 3, 5, 2, 3, 2]), array([3, 1, 3, 5, 3, 2, 2]), array([3, 1, 3, 5, 3, 3, 2]), array([3, 1, 4, 4, 1, 3, 2]), array([3, 1, 4, 4, 2, 2, 2]), array([3, 1, 4, 4, 2, 3, 2]), array([3, 1, 4, 4, 3, 2, 2]), array([3, 1, 4, 4, 3, 3, 2]), array([3, 1, 4, 5, 1, 3, 2]), array([3, 1, 4, 5, 2, 2, 2]), array([3, 1, 4, 5, 2, 3, 2]), array([3, 1, 4, 5, 3, 2, 2]), array([3, 1, 4, 5, 3, 3, 2]), array([3, 1, 5, 4, 1, 3, 2]), array([3, 1, 5, 4, 2, 2, 2]), array([3, 1, 5, 4, 2, 3, 2]), array([3, 1, 5, 4, 3, 2, 2]), array([3, 1, 5, 4, 3, 3, 2]), array([3, 1, 5, 5, 1, 3, 2]), array([3, 1, 5, 5, 2, 2, 2]), array([3, 1, 5, 5, 2, 3, 2]), array([3, 1, 5, 5, 3, 2, 2]), array([3, 1, 5, 5, 3, 3, 2]), array([2, 4, 2, 4, 1, 3, 2]), array([2, 4, 2, 4, 2, 3, 2]), array([2, 4, 2, 4, 3, 2, 2]), array([2, 4, 2, 4, 3, 3, 2]), array([2, 4, 2, 5, 2, 3, 2]), array([2, 4, 2, 5, 3, 2, 2]), array([2, 4, 2, 5, 3, 3, 2]), array([2, 4, 3, 4, 1, 3, 2]), array([2, 4, 3, 4, 2, 3, 2]), array([2, 4, 3, 4, 3, 2, 2]), array([2, 4, 3, 4, 3, 3, 2]), array([2, 4, 3, 5, 1, 3, 2]), array([2, 4, 3, 5, 2, 2, 2]), array([2, 4, 3, 5, 2, 3, 2]), array([2, 4, 3, 5, 3, 2, 2]), array([2, 4, 3, 5, 3, 3, 2]), array([2, 4, 4, 4, 1, 3, 2]), array([2, 4, 4, 4, 2, 2, 2]), array([2, 4, 4, 4, 2, 3, 2]), array([2, 4, 4, 4, 3, 2, 2]), array([2, 4, 4, 4, 3, 3, 2]), array([2, 4, 4, 5, 1, 3, 2]), array([2, 4, 4, 5, 2, 2, 2]), array([2, 4, 4, 5, 2, 3, 2]), array([2, 4, 4, 5, 3, 2, 2]), array([2, 4, 4, 5, 3, 3, 2]), array([2, 4, 5, 4, 1, 3, 2]), array([2, 4, 5, 4, 2, 2, 2]), array([2, 4, 5, 4, 2, 3, 2]), array([2, 4, 5, 4, 3, 2, 2]), array([2, 4, 5, 4, 3, 3, 2]), array([2, 4, 5, 5, 1, 3, 2]), array([2, 4, 5, 5, 2, 2, 2]), array([2, 4, 5, 5, 2, 3, 2]), array([2, 4, 5, 5, 3, 2, 2]), array([2, 4, 5, 5, 3, 3, 2]), array([2, 3, 2, 4, 1, 3, 2]), array([2, 3, 2, 4, 2, 3, 2]), array([2, 3, 2, 4, 3, 2, 2]), array([2, 3, 2, 4, 3, 3, 2]), array([2, 3, 2, 5, 2, 3, 2]), array([2, 3, 2, 5, 3, 2, 2]), array([2, 3, 2, 5, 3, 3, 2]), array([2, 3, 3, 4, 1, 3, 2]), array([2, 3, 3, 4, 2, 3, 2]), array([2, 3, 3, 4, 3, 2, 2]), array([2, 3, 3, 4, 3, 3, 2]), array([2, 3, 3, 5, 1, 3, 2]), array([2, 3, 3, 5, 2, 2, 2]), array([2, 3, 3, 5, 2, 3, 2]), array([2, 3, 3, 5, 3, 2, 2]), array([2, 3, 3, 5, 3, 3, 2]), array([2, 3, 4, 4, 1, 3, 2]), array([2, 3, 4, 4, 2, 2, 2]), array([2, 3, 4, 4, 2, 3, 2]), array([2, 3, 4, 4, 3, 2, 2]), array([2, 3, 4, 4, 3, 3, 2]), array([2, 3, 4, 5, 1, 3, 2]), array([2, 3, 4, 5, 2, 2, 2]), array([2, 3, 4, 5, 2, 3, 2]), array([2, 3, 4, 5, 3, 2, 2]), array([2, 3, 4, 5, 3, 3, 2]), array([2, 3, 5, 4, 1, 3, 2]), array([2, 3, 5, 4, 2, 2, 2]), array([2, 3, 5, 4, 2, 3, 2]), array([2, 3, 5, 4, 3, 2, 2]), array([2, 3, 5, 4, 3, 3, 2]), array([2, 3, 5, 5, 1, 3, 2]), array([2, 3, 5, 5, 2, 2, 2]), array([2, 3, 5, 5, 2, 3, 2]), array([2, 3, 5, 5, 3, 2, 2]), array([2, 3, 5, 5, 3, 3, 2]), array([2, 2, 2, 4, 1, 2, 2]), array([2, 2, 2, 4, 1, 3, 2]), array([2, 2, 2, 4, 2, 2, 2]), array([2, 2, 2, 4, 2, 3, 2]), array([2, 2, 2, 4, 3, 2, 2]), array([2, 2, 2, 5, 2, 2, 2]), array([2, 2, 2, 5, 2, 3, 2]), array([2, 2, 2, 5, 3, 2, 2]), array([2, 2, 3, 4, 1, 2, 2]), array([2, 2, 3, 4, 1, 3, 2]), array([2, 2, 3, 4, 2, 2, 2]), array([2, 2, 3, 4, 2, 3, 2]), array([2, 2, 3, 4, 3, 2, 2]), array([2, 2, 3, 5, 1, 2, 2]), array([2, 2, 3, 5, 1, 3, 2]), array([2, 2, 3, 5, 2, 2, 2]), array([2, 2, 3, 5, 3, 2, 2]), array([2, 2, 4, 4, 1, 2, 2]), array([2, 2, 4, 4, 1, 3, 2]), array([2, 2, 4, 4, 2, 2, 2]), array([2, 2, 4, 4, 3, 2, 2]), array([2, 2, 4, 5, 1, 2, 2]), array([2, 2, 4, 5, 1, 3, 2]), array([2, 2, 4, 5, 2, 2, 2]), array([2, 2, 4, 5, 3, 2, 2]), array([2, 2, 5, 4, 1, 2, 2]), array([2, 2, 5, 4, 1, 3, 2]), array([2, 2, 5, 4, 2, 2, 2]), array([2, 2, 5, 4, 3, 2, 2]), array([2, 2, 5, 5, 1, 2, 2]), array([2, 2, 5, 5, 1, 3, 2]), array([2, 2, 5, 5, 2, 2, 2]), array([2, 2, 5, 5, 3, 2, 2]), array([2, 1, 2, 4, 1, 2, 2]), array([2, 1, 2, 4, 2, 2, 2]), array([2, 1, 2, 5, 2, 2, 2]), array([2, 1, 3, 4, 1, 2, 2]), array([2, 1, 3, 4, 2, 2, 2]), array([2, 1, 3, 5, 1, 2, 2]), array([2, 1, 4, 4, 1, 2, 2]), array([2, 1, 4, 5, 1, 2, 2]), array([2, 1, 5, 4, 1, 2, 2]), array([2, 1, 5, 5, 1, 2, 2]), array([1, 4, 2, 4, 1, 3, 2]), array([1, 4, 2, 4, 2, 3, 2]), array([1, 4, 2, 4, 3, 2, 2]), array([1, 4, 2, 4, 3, 3, 2]), array([1, 4, 2, 5, 2, 3, 2]), array([1, 4, 2, 5, 3, 2, 2]), array([1, 4, 2, 5, 3, 3, 2]), array([1, 4, 3, 4, 1, 3, 2]), array([1, 4, 3, 4, 2, 3, 2]), array([1, 4, 3, 4, 3, 2, 2]), array([1, 4, 3, 4, 3, 3, 2]), array([1, 4, 3, 5, 1, 3, 2]), array([1, 4, 3, 5, 2, 2, 2]), array([1, 4, 3, 5, 2, 3, 2]), array([1, 4, 3, 5, 3, 2, 2]), array([1, 4, 3, 5, 3, 3, 2]), array([1, 4, 4, 4, 1, 3, 2]), array([1, 4, 4, 4, 2, 2, 2]), array([1, 4, 4, 4, 2, 3, 2]), array([1, 4, 4, 4, 3, 2, 2]), array([1, 4, 4, 4, 3, 3, 2]), array([1, 4, 4, 5, 1, 3, 2]), array([1, 4, 4, 5, 2, 2, 2]), array([1, 4, 4, 5, 2, 3, 2]), array([1, 4, 4, 5, 3, 2, 2]), array([1, 4, 4, 5, 3, 3, 2]), array([1, 4, 5, 4, 1, 3, 2]), array([1, 4, 5, 4, 2, 2, 2]), array([1, 4, 5, 4, 2, 3, 2]), array([1, 4, 5, 4, 3, 2, 2]), array([1, 4, 5, 4, 3, 3, 2]), array([1, 4, 5, 5, 1, 3, 2]), array([1, 4, 5, 5, 2, 2, 2]), array([1, 4, 5, 5, 2, 3, 2]), array([1, 4, 5, 5, 3, 2, 2]), array([1, 4, 5, 5, 3, 3, 2]), array([1, 3, 2, 4, 1, 2, 2]), array([1, 3, 2, 4, 1, 3, 2]), array([1, 3, 2, 4, 2, 2, 2]), array([1, 3, 2, 4, 2, 3, 2]), array([1, 3, 2, 4, 3, 2, 2]), array([1, 3, 2, 5, 2, 2, 2]), array([1, 3, 2, 5, 2, 3, 2]), array([1, 3, 2, 5, 3, 2, 2]), array([1, 3, 3, 4, 1, 2, 2]), array([1, 3, 3, 4, 1, 3, 2]), array([1, 3, 3, 4, 2, 2, 2]), array([1, 3, 3, 4, 2, 3, 2]), array([1, 3, 3, 4, 3, 2, 2]), array([1, 3, 3, 5, 1, 2, 2]), array([1, 3, 3, 5, 1, 3, 2]), array([1, 3, 3, 5, 2, 2, 2]), array([1, 3, 3, 5, 3, 2, 2]), array([1, 3, 4, 4, 1, 2, 2]), array([1, 3, 4, 4, 1, 3, 2]), array([1, 3, 4, 4, 2, 2, 2]), array([1, 3, 4, 4, 3, 2, 2]), array([1, 3, 4, 5, 1, 2, 2]), array([1, 3, 4, 5, 1, 3, 2]), array([1, 3, 4, 5, 2, 2, 2]), array([1, 3, 4, 5, 3, 2, 2]), array([1, 3, 5, 4, 1, 2, 2]), array([1, 3, 5, 4, 1, 3, 2]), array([1, 3, 5, 4, 2, 2, 2]), array([1, 3, 5, 4, 3, 2, 2]), array([1, 3, 5, 5, 1, 2, 2]), array([1, 3, 5, 5, 1, 3, 2]), array([1, 3, 5, 5, 2, 2, 2]), array([1, 3, 5, 5, 3, 2, 2]), array([1, 2, 2, 4, 1, 2, 2]), array([1, 2, 2, 4, 2, 2, 2]), array([1, 2, 2, 5, 2, 2, 2]), array([1, 2, 3, 4, 1, 2, 2]), array([1, 2, 3, 4, 2, 2, 2]), array([1, 2, 3, 5, 1, 2, 2]), array([1, 2, 4, 4, 1, 2, 2]), array([1, 2, 4, 5, 1, 2, 2]), array([1, 2, 5, 4, 1, 2, 2]), array([1, 2, 5, 5, 1, 2, 2]), array([1, 1, 2, 4, 1, 2, 2]), array([1, 1, 2, 4, 2, 2, 2]), array([1, 1, 2, 5, 2, 2, 2]), array([1, 1, 3, 4, 1, 2, 2]), array([1, 1, 3, 4, 2, 2, 2]), array([1, 1, 3, 5, 1, 2, 2]), array([1, 1, 4, 4, 1, 2, 2]), array([1, 1, 4, 5, 1, 2, 2]), array([1, 1, 5, 4, 1, 2, 2]), array([1, 1, 5, 5, 1, 2, 2])]), (4, [array([2, 2, 2, 4, 3, 3, 4]), array([2, 2, 2, 5, 3, 3, 4]), array([2, 2, 3, 4, 3, 3, 4]), array([2, 2, 3, 5, 2, 3, 4]), array([2, 2, 3, 5, 3, 3, 4]), array([2, 2, 4, 4, 2, 3, 4]), array([2, 2, 4, 4, 3, 3, 4]), array([2, 2, 4, 5, 2, 3, 4]), array([2, 2, 4, 5, 3, 3, 4]), array([2, 2, 5, 4, 2, 3, 4]), array([2, 2, 5, 4, 3, 3, 4]), array([2, 2, 5, 5, 2, 3, 4]), array([2, 2, 5, 5, 3, 3, 4]), array([2, 1, 2, 4, 3, 3, 4]), array([2, 1, 2, 5, 3, 3, 4]), array([2, 1, 3, 4, 3, 3, 4]), array([2, 1, 3, 5, 2, 3, 4]), array([2, 1, 3, 5, 3, 3, 4]), array([2, 1, 4, 4, 2, 3, 4]), array([2, 1, 4, 4, 3, 3, 4]), array([2, 1, 4, 5, 2, 3, 4]), array([2, 1, 4, 5, 3, 3, 4]), array([2, 1, 5, 4, 2, 3, 4]), array([2, 1, 5, 4, 3, 3, 4]), array([2, 1, 5, 5, 2, 3, 4]), array([2, 1, 5, 5, 3, 3, 4]), array([1, 3, 2, 4, 3, 3, 4]), array([1, 3, 2, 5, 3, 3, 4]), array([1, 3, 3, 4, 3, 3, 4]), array([1, 3, 3, 5, 2, 3, 4]), array([1, 3, 3, 5, 3, 3, 4]), array([1, 3, 4, 4, 2, 3, 4]), array([1, 3, 4, 4, 3, 3, 4]), array([1, 3, 4, 5, 2, 3, 4]), array([1, 3, 4, 5, 3, 3, 4]), array([1, 3, 5, 4, 2, 3, 4]), array([1, 3, 5, 4, 3, 3, 4]), array([1, 3, 5, 5, 2, 3, 4]), array([1, 3, 5, 5, 3, 3, 4]), array([1, 2, 2, 4, 3, 3, 4]), array([1, 2, 2, 5, 3, 3, 4]), array([1, 2, 3, 4, 3, 3, 4]), array([1, 2, 3, 5, 2, 3, 4]), array([1, 2, 3, 5, 3, 3, 4]), array([1, 2, 4, 4, 2, 3, 4]), array([1, 2, 4, 4, 3, 3, 4]), array([1, 2, 4, 5, 2, 3, 4]), array([1, 2, 4, 5, 3, 3, 4]), array([1, 2, 5, 4, 2, 3, 4]), array([1, 2, 5, 4, 3, 3, 4]), array([1, 2, 5, 5, 2, 3, 4]), array([1, 2, 5, 5, 3, 3, 4]), array([1, 1, 2, 4, 3, 3, 4]), array([1, 1, 2, 5, 3, 3, 4]), array([1, 1, 3, 4, 3, 3, 4]), array([1, 1, 3, 5, 2, 3, 4]), array([1, 1, 3, 5, 3, 3, 4]), array([1, 1, 4, 4, 2, 3, 4]), array([1, 1, 4, 4, 3, 3, 4]), array([1, 1, 4, 5, 2, 3, 4]), array([1, 1, 4, 5, 3, 3, 4]), array([1, 1, 5, 4, 2, 3, 4]), array([1, 1, 5, 4, 3, 3, 4]), array([1, 1, 5, 5, 2, 3, 4]), array([1, 1, 5, 5, 3, 3, 4])]), (3, [array([2, 1, 2, 4, 1, 3, 3]), array([2, 1, 2, 4, 2, 3, 3]), array([2, 1, 2, 4, 3, 2, 3]), array([2, 1, 2, 5, 2, 3, 3]), array([2, 1, 2, 5, 3, 2, 3]), array([2, 1, 3, 4, 1, 3, 3]), array([2, 1, 3, 4, 2, 3, 3]), array([2, 1, 3, 4, 3, 2, 3]), array([2, 1, 3, 5, 1, 3, 3]), array([2, 1, 3, 5, 2, 2, 3]), array([2, 1, 3, 5, 3, 2, 3]), array([2, 1, 4, 4, 1, 3, 3]), array([2, 1, 4, 4, 2, 2, 3]), array([2, 1, 4, 4, 3, 2, 3]), array([2, 1, 4, 5, 1, 3, 3]), array([2, 1, 4, 5, 2, 2, 3]), array([2, 1, 4, 5, 3, 2, 3]), array([2, 1, 5, 4, 1, 3, 3]), array([2, 1, 5, 4, 2, 2, 3]), array([2, 1, 5, 4, 3, 2, 3]), array([2, 1, 5, 5, 1, 3, 3]), array([2, 1, 5, 5, 2, 2, 3]), array([2, 1, 5, 5, 3, 2, 3]), array([1, 2, 2, 4, 1, 3, 3]), array([1, 2, 2, 4, 2, 3, 3]), array([1, 2, 2, 4, 3, 2, 3]), array([1, 2, 2, 5, 2, 3, 3]), array([1, 2, 2, 5, 3, 2, 3]), array([1, 2, 3, 4, 1, 3, 3]), array([1, 2, 3, 4, 2, 3, 3]), array([1, 2, 3, 4, 3, 2, 3]), array([1, 2, 3, 5, 1, 3, 3]), array([1, 2, 3, 5, 2, 2, 3]), array([1, 2, 3, 5, 3, 2, 3]), array([1, 2, 4, 4, 1, 3, 3]), array([1, 2, 4, 4, 2, 2, 3]), array([1, 2, 4, 4, 3, 2, 3]), array([1, 2, 4, 5, 1, 3, 3]), array([1, 2, 4, 5, 2, 2, 3]), array([1, 2, 4, 5, 3, 2, 3]), array([1, 2, 5, 4, 1, 3, 3]), array([1, 2, 5, 4, 2, 2, 3]), array([1, 2, 5, 4, 3, 2, 3]), array([1, 2, 5, 5, 1, 3, 3]), array([1, 2, 5, 5, 2, 2, 3]), array([1, 2, 5, 5, 3, 2, 3]), array([1, 1, 2, 4, 1, 3, 3]), array([1, 1, 2, 4, 2, 3, 3]), array([1, 1, 2, 4, 3, 2, 3]), array([1, 1, 2, 5, 2, 3, 3]), array([1, 1, 2, 5, 3, 2, 3]), array([1, 1, 3, 4, 1, 3, 3]), array([1, 1, 3, 4, 2, 3, 3]), array([1, 1, 3, 4, 3, 2, 3]), array([1, 1, 3, 5, 1, 3, 3]), array([1, 1, 3, 5, 2, 2, 3]), array([1, 1, 3, 5, 3, 2, 3]), array([1, 1, 4, 4, 1, 3, 3]), array([1, 1, 4, 4, 2, 2, 3]), array([1, 1, 4, 4, 3, 2, 3]), array([1, 1, 4, 5, 1, 3, 3]), array([1, 1, 4, 5, 2, 2, 3]), array([1, 1, 4, 5, 3, 2, 3]), array([1, 1, 5, 4, 1, 3, 3]), array([1, 1, 5, 4, 2, 2, 3]), array([1, 1, 5, 4, 3, 2, 3]), array([1, 1, 5, 5, 1, 3, 3]), array([1, 1, 5, 5, 2, 2, 3]), array([1, 1, 5, 5, 3, 2, 3])])])\n",
      "\n",
      "Média e Desvio de cada atributo:\n",
      " \n",
      "Sumário dos atributos: \n",
      "[(2.5, 1.1183576344329658), (2.5, 1.1183576344329658), (3.5, 1.1183576344329658), (3.6666666666666665, 1.2475801707990428), (2.0, 0.8167329383160689), (2.0, 0.8167329383160689)]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Média e Desvio padrão de cada atributo separado por Classe: \n",
      "\n",
      "Resumo por classe:                                      1                                    2  \\\n",
      "0   (2.64472049689, 1.129869264501616)   (2.45038167939, 1.041026169674228)   \n",
      "1  (2.63105590062, 1.1348305166841455)  (2.43129770992, 1.0545710732696536)   \n",
      "2  (3.47577639752, 1.1355722907642973)   (3.63740458015, 1.073100987050176)   \n",
      "3    (3.33540372671, 1.29745301288057)  (4.51908396947, 0.5005919107629965)   \n",
      "4  (1.95527950311, 0.8198334848767311)  (2.12595419847, 0.7947228039127456)   \n",
      "5  (1.74161490683, 0.7997635694014096)  (2.52290076336, 0.5004312141304175)   \n",
      "\n",
      "                                     3                                     4  \n",
      "0  (1.38636363636, 0.4925448434741561)  (1.39130434783, 0.49343516379516916)  \n",
      "1  (1.29545454545, 0.4615215208036401)      (1.78260869565, 0.7575704874652)  \n",
      "2            (3.5, 1.1309596665849142)     (3.71739130435, 1.12867756400057)  \n",
      "3            (4.5, 0.5057805388588732)  (4.60869565217, 0.49343516379516916)  \n",
      "4  (2.09090909091, 0.7414060124279211)    (2.58695652174, 0.497821340398864)  \n",
      "5  (2.38636363636, 0.4925448434741562)                            (3.0, 0.0)  \n",
      "\n",
      " {3: [(1.3863636363636365, 0.4925448434741561), (1.2954545454545454, 0.4615215208036401), (3.5, 1.1309596665849142), (4.5, 0.5057805388588732), (2.0909090909090908, 0.7414060124279211), (2.3863636363636362, 0.4925448434741562)], 2: [(2.4503816793893129, 1.041026169674228), (2.4312977099236641, 1.0545710732696536), (3.6374045801526718, 1.073100987050176), (4.5190839694656493, 0.5005919107629965), (2.1259541984732824, 0.7947228039127456), (2.5229007633587788, 0.5004312141304175)], 1: [(2.64472049689441, 1.129869264501616), (2.631055900621118, 1.1348305166841455), (3.4757763975155278, 1.1355722907642973), (3.3354037267080745, 1.29745301288057), (1.9552795031055901, 0.8198334848767311), (1.7416149068322981, 0.7997635694014096)], 4: [(1.3913043478260869, 0.49343516379516916), (1.7826086956521738, 0.7575704874652), (3.7173913043478262, 1.12867756400057), (4.6086956521739131, 0.49343516379516916), (2.5869565217391304, 0.497821340398864), (3.0, 0.0)]}\n",
      "\n",
      " Resultado - Predição de Classe para o Teste: \n",
      "     0  1  2  3  4  5  6\n",
      "1   4  4  2  2  1  2  1\n",
      "2   4  4  2  4  2  3  1\n",
      "1   4  4  2  4  3  1  1\n",
      "1   4  4  2  5  1  1  1\n",
      "1   4  4  3  2  1  3  1\n",
      "1   4  4  3  2  2  1  1\n",
      "1   4  4  3  2  2  2  1\n",
      "1   4  4  3  2  2  3  1\n",
      "1   4  4  3  4  1  2  1\n",
      "1   4  4  3  4  2  1  1\n",
      "2   4  4  3  4  2  3  1\n",
      "1   4  4  3  4  3  1  1\n",
      "2   4  4  3  4  3  3  1\n",
      "2   4  4  3  5  2  2  1\n",
      "2   4  4  3  5  2  3  1\n",
      "1   4  4  3  5  3  1  1\n",
      "2   4  4  3  5  3  3  1\n",
      "1   4  4  4  2  2  1  1\n",
      "1   4  4  4  2  3  2  1\n",
      "1   4  4  4  4  1  1  1\n",
      "2   4  4  4  4  2  2  1\n",
      "1   4  4  4  4  3  1  1\n",
      "2   4  4  4  4  3  2  1\n",
      "1   4  4  4  5  2  1  1\n",
      "2   4  4  4  5  3  2  1\n",
      "1   4  4  5  2  1  1  1\n",
      "1   4  4  5  2  1  3  1\n",
      "1   4  4  5  2  2  1  1\n",
      "1   4  4  5  2  3  1  1\n",
      "1   4  4  5  4  2  1  1\n",
      ".. .. .. .. .. .. .. ..\n",
      "3   1  1  2  5  2  1  1\n",
      "3   1  1  2  5  2  2  2\n",
      "3   1  1  2  5  3  1  1\n",
      "3   1  1  2  5  3  2  3\n",
      "1   1  1  3  2  1  2  1\n",
      "1   1  1  3  2  2  2  1\n",
      "1   1  1  3  2  2  3  1\n",
      "1   1  1  3  2  3  1  1\n",
      "1   1  1  3  2  3  2  1\n",
      "1   1  1  3  2  3  3  1\n",
      "3   1  1  3  4  1  2  2\n",
      "3   1  1  3  4  1  3  3\n",
      "3   1  1  3  4  3  3  4\n",
      "3   1  1  3  5  3  2  3\n",
      "3   1  1  4  4  1  1  1\n",
      "3   1  1  4  4  1  2  2\n",
      "3   1  1  4  4  1  3  3\n",
      "3   1  1  4  4  2  2  3\n",
      "3   1  1  4  4  3  2  3\n",
      "3   1  1  4  5  1  2  2\n",
      "3   1  1  4  5  2  1  1\n",
      "3   1  1  4  5  2  3  4\n",
      "3   1  1  4  5  3  3  4\n",
      "1   1  1  5  2  1  2  1\n",
      "1   1  1  5  2  1  3  1\n",
      "1   1  1  5  2  3  1  1\n",
      "3   1  1  5  4  1  2  2\n",
      "3   1  1  5  4  3  2  3\n",
      "3   1  1  5  4  3  3  4\n",
      "3   1  1  5  5  1  3  3\n",
      "\n",
      "[571 rows x 7 columns]\n",
      "\n",
      "Acurácia: 80.56042031523643\n"
     ]
    }
   ],
   "source": [
    "###QUESTAO 1#########\n",
    "\n",
    "filename='car.data'\n",
    "dataset=loadCsv(filename)\n",
    "\n",
    "dataset1=pd.DataFrame(dataset)\n",
    "mapping = {'vhigh':4, 'high':3, 'med':2, 'low':1, '2':2, '3':3, '4':4, '5more':5, '2':2, '4':4, 'more':5,'small':1,'med':2, 'big':3,'low':1, 'med':2, 'high':3,'unacc':1, 'acc':2, 'good':3, 'vgood':4}\n",
    "\n",
    "data=dataset1.applymap(lambda s: mapping.get(s) if s in mapping else s)\n",
    "\n",
    "data1=data.values\n",
    "dataList=list(data1)\n",
    "\n",
    "#In [9]: mapping = {'set': 1, 'test': 2}\n",
    "#In [10]: df.replace({'set': mapping, 'tesst': mapping})\n",
    "#df.applymap(lambda s: mymap.get(s) if s in mymap else s)\n",
    "\n",
    "print(('Arquivo carregado {0} com {1} linhas').format(filename,len(dataset)))\n",
    "#print((\"\\n{0}\").format(dataset1))\n",
    "print((\"\\n{0}\").format(data1))\n",
    "\n",
    "splitRatio=0.67\n",
    "train, test = splitDataset(dataList, splitRatio)\n",
    "\n",
    "byClass=separateByClass(dataList)\n",
    "byClassI=byClass.items()\n",
    "print(byClassI)\n",
    "\n",
    "summary=summarize(dataList)\n",
    "print(\"\\nMédia e Desvio de cada atributo:\\n \")\n",
    "print((\"Sumário dos atributos: \\n{0}\").format(summary))\n",
    "\n",
    "summary=summarizeByClass(train)\n",
    "summary1=pd.DataFrame(summary)\n",
    "print(\"\\nMédia e Desvio padrão de cada atributo separado por Classe: \\n\")\n",
    "print((\"Resumo por classe: {0}\").format(summary1))\n",
    "\n",
    "\n",
    "print((\"\\n {0}\").format(summary))\n",
    "summaries=summary\n",
    "\n",
    "\n",
    "inputVector = test\n",
    "predictions=getPredictions(summary, inputVector)\n",
    "predictions1=pd.DataFrame(inputVector,predictions)\n",
    "print((\"\\n Resultado - Predição de Classe para o Teste: \\n {0}\").format(predictions1))\n",
    "# print((\"Entrada {0} Consulta: {1} Predição Classe {2}\").format(summary,inputVector,result))\n",
    "\n",
    "accuracy=getAccuracy(test,predictions)\n",
    "print((\"\\nAcurácia: {0}\").format(accuracy))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Questão 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from sklearn.naive_bayes import GaussianNB\n",
    "import numpy as np\n",
    "from sklearn.model_selection import GridSearchCV\n",
    "from sklearn.metrics import confusion_matrix\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.metrics import accuracy_score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "filename='car.data'\n",
    "dataset=loadCsv(filename)\n",
    "\n",
    "dataset1=pd.DataFrame(dataset)\n",
    "mapping = {'vhigh':4, 'high':3, 'med':2, 'low':1, '2':2, '3':3, '4':4, '5more':5, '2':2, '4':4, 'more':5,'small':1,'med':2, 'big':3,'low':1, 'med':2, 'high':3,'unacc':1, 'acc':2, 'good':3, 'vgood':4}\n",
    "\n",
    "data=dataset1.applymap(lambda s: mapping.get(s) if s in mapping else s)\n",
    "\n",
    "data1=data.values\n",
    "df = pd.DataFrame(data1,columns=range(7))\n",
    "\n",
    "# ds = loadCsv(\"carData.csv\")\n",
    "# df = pd.DataFrame(ds, columns=range(7))\n",
    "\n",
    "X = df[list(range(6))]\n",
    "y = df[6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "acuracias = []\n",
    "\n",
    "for x in range(100):\n",
    "\n",
    "# Particionamento do dataset\n",
    "    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.33)\n",
    "#     print(X_train, X_test, y_train, y_test)\n",
    "    nb = GaussianNB()\n",
    "    nb.fit(X_train, y_train)\n",
    "    \n",
    "# Acurácia\n",
    "    acuracia = accuracy_score(y_test, nb.predict(X_test))\n",
    "    acuracias.append(acuracia)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "count    100.000000\n",
       "mean       0.768371\n",
       "std        0.014992\n",
       "min        0.732049\n",
       "25%        0.760070\n",
       "50%        0.768827\n",
       "75%        0.777583\n",
       "max        0.803853\n",
       "dtype: float64"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.Series(acuracias).describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
